What do I use and where do I use it?
1 view (last 30 days)
Show older comments
rgbImage = imread(fullFileName);
imshow(rgbImage); set(gcf, 'units','normalized','outerposition',[0 0 1 1]); drawnow;
[rows, columns, numberOfColorBands] = size(rgbImage); blockSizeR = 40; %Rows in block.
blockSizeC = 40; %Rows in column.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
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); fileID = fopen('AB_45.xls','wt'); NewID = 'Book1.xls';
numbers = [];
for r = 1 : numPlotsR
for c = 1 : numPlotsC
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;
img1=rgbBlock;
imshow(img1)
img2=imbinarize(img1,graythresh(img1)); imshow(img2)
img2=~img2; imshow(img2)
B = bwboundaries(img2); imshow(img2)
numbers = [numbers ; (length(B))];
hold on
for k = 1:length(B)
boundary = B{k};
text(10,10,strcat('\color{green}',num2str(length(B))))
fprintf(' \n');
end
end
end
xlswrite(NewID,numbers,1,'A1:AN40');
3 Comments
Geoff Hayes
on 7 Feb 2019
What is numbers being set to on each iteration of the loop? Please show your updated code.
Answers (1)
Image Analyst
on 7 Feb 2019
Assign numbers like this:
numbers(plotIndex) = length(B);
You need to define newID.
Also, call xlswrite() just once after your double for loop.
And your look over k just puts up a label for each boundary in the same place at (10,10), which seems unwise.
See Also
Categories
Find more on Spreadsheets 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!