What do I use and where do I use it?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2019-2-7
What is numbers being set to on each iteration of the loop? Please show your updated code.
回答(1 个)
Image Analyst
2019-2-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!