Divide an image into 16x128x128 tiles each

조회 수: 1 (최근 30일)
Warid Islam
Warid Islam 2022년 4월 5일
답변: Animesh Gupta 2022년 8월 30일
Hi,
I have an image which I want to divide into several blocks as defined in sample.png. This image file is just a demo image like whom I want to divide my original image CCffdmdatabase1.png. I want to divide my oroginal image file into the same way as shown in sample.png. I am planning to analyze each block separately later. I tried the following line of code. My final image is shown in result.png. This file is different from the sample.png file. Any suggestions would be appreciated.
rgbImage = imread('CCffdmdatabase1.png');
% For demo purposes, let's resize it to be 64 by 64;
rgbImage = imresize(rgbImage, [64 64]);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage)
ca = mat2cell(rgbImage,8*ones(1,size(rgbImage,1)/8),8*ones(1,size(rgbImage,2)/8),3);
plotIndex = 1;
for c = 1 : size(ca, 2)
for r = 1 : size(ca, 1)
fprintf('c=%d, r=%d\n', c, r);
subplot(8,8,plotIndex);
imshow(ca{r,c});
plotIndex = plotIndex + 1
end
end
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
  댓글 수: 2
DGM
DGM 2022년 4월 5일
What's wrong with the method you're using? Is there something else specific that needs to be done?
Warid Islam
Warid Islam 2022년 4월 6일
Hi @DGM,
I want to apply the attention based multiple instance learning to analyze those images. This process requries to divide each images into several instances and put them in a bag.
The link above explains the process further.

댓글을 달려면 로그인하십시오.

답변 (1개)

Animesh Gupta
Animesh Gupta 2022년 8월 30일
Hello,
It is my understanding that you want to divide the image into several blocks.
The idea is to extract the interested rows and columns for that part of the image, for which the block represents.
That is, for the 1st block, it should extract rows of index [1,8], columns of index [1,8] and for 2nd block it should extract rows of index [1,8], columns of the index [2,9], and so on.
You may refer the following script to undestand this procedure.
M1 = imread("CCffdmdatabase1.png");
J = imresize(M1, [64 64]);
[numRows, numCols, numChannels] = size(J);
blockSize = 8; % Block Size (32x32)
index = 1;
for i = 1:(numRows/blockSize)
for j = 1:(numCols/blockSize)
imageTile = J((blockSize * (i-1) + 1 : blockSize * (i-1) + blockSize), ... % number of rows
(blockSize * (j-1) + 1 : blockSize * (j-1) + blockSize), ... % number of columns
: ... % to include all the channels
); % interested image for the block at index position
subplot(numRows/blockSize, numCols/blockSize, index); % for creating a subplot as a tile in 8X8 plot
imshow(imageTile);
index = index + 1;
end
end
I hope it helps.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by