Clear Filters
Clear Filters

How do I store patches in order?

2 views (last 30 days)
Md Farhad Mokter
Md Farhad Mokter on 11 Jun 2019
Commented: Md Farhad Mokter on 13 Jun 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 Comments
Image Analyst
Image Analyst on 12 Jun 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 on 13 Jun 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.

Sign in to comment.

Answers (0)

Categories

Find more on Display Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!