Effacer les filtres
Effacer les filtres

How do I store patches in order?

2 vues (au cours des 30 derniers jours)
Md Farhad Mokter
Md Farhad Mokter le 11 Juin 2019
Commenté : Md Farhad Mokter le 13 Juin 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 commentaires
Image Analyst
Image Analyst le 12 Juin 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 le 13 Juin 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Display Image dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by