Azzera filtri
Azzera filtri

How do I store patches in order?

2 visualizzazioni (ultimi 30 giorni)
Md Farhad Mokter
Md Farhad Mokter il 11 Giu 2019
Commentato: Md Farhad Mokter il 13 Giu 2019
I am the given code for creating 28*28 patches from a 224*224 image.
fullFileName='sample.bmp';
rgbImage = imread(fullFileName);
imshow(rgbImage);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
[rows columns numberOfColorBands] = size(rgbImage)
blockSizeR = 28; % Rows in block.
blockSizeC = 28; % Columns in block.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows)];
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols)];
if numberOfColorBands > 1
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
subplot(numPlotsR, numPlotsC, plotIndex);
rgbBlock = ca{r,c};
imshow(rgbBlock);
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
caption = sprintf('Block #%d of %d\n%d rows by %d columns', ...
plotIndex, numPlotsR*numPlotsC, rowsB, columnsB);
title(caption);
drawnow;
plotIndex = plotIndex + 1;
end
end
Now I want to store those patches in the order they are created, so that, for first row there are 8 patches and second row starts with 9th patch. I also want to store those patches with same name as original image with an extension at the end. For example if the image name is sample.bmp, the patches should be named like sample_01, sample_02...like this.
  3 Commenti
Image Analyst
Image Analyst il 12 Giu 2019
Maybe he wants to save them as new images to disk, so those are filenames, rather than creating variables with that name. Maybe the poster can clarify what "store" means to him.
Md Farhad Mokter
Md Farhad Mokter il 13 Giu 2019
I want to save each of the patches as an image file in my disk. For each input image, I want to get 64 patches with same name as original file.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Display Image in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by