Divide an image into 16x128x128 tiles each

1 visualizzazione (ultimi 30 giorni)
Warid Islam
Warid Islam il 5 Apr 2022
Risposto: Animesh Gupta il 30 Ago 2022
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 Commenti
DGM
DGM il 5 Apr 2022
What's wrong with the method you're using? Is there something else specific that needs to be done?
Warid Islam
Warid Islam il 6 Apr 2022
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.

Accedi per commentare.

Risposte (1)

Animesh Gupta
Animesh Gupta il 30 Ago 2022
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.

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by