calculating the percentage and displaying
59 次查看(过去 30 天)
显示 更早的评论
I have a 256*256 matrix consisting of ones and two's for example i have a 4x4matrix
A=[1 2 2 1
1 2 1 1
2 2 2 1
1 1 1 1 ]
in the A matrix i want to calculate the percentage of ones and two's
i have 10 number of 1's (10/16*100) so i want to display as
62.5% same_value
37.5%others
please help
0 个评论
采纳的回答
Image Analyst
2012-10-5
Try this:
A=[1 2 2 1
1 2 1 1
2 2 2 1
1 1 1 1 ]
numberOfBins = max(A(:));
countsPercentage = 100 * hist(A(:), numberOfBins) / numel(A)
In the command window:
A =
1 2 2 1
1 2 1 1
2 2 2 1
1 1 1 1
countsPercentage =
62.5 37.5
5 个评论
Image Analyst
2012-10-5
编辑:Image Analyst
2012-10-5
I printed out to the command window exactly what you said you need: "i need as...." and "i need to display...."
I edited the above code in the above comment to add the \n to put them on separate lines. Try again.
nor azam
2019-5-15
编辑:nor azam
2019-5-15
Hi Image Analyst, what if i want to print the value along with the image. Means that i used imshow to show the image and i want to print the percentage on the image. Is there any other way? please help me.
Here is my code after binarize.
BW2 = imbinarize(rightHalf)
figure;
imshowpair(rightHalf,BW2,'montage')
percentageBlackRight=(1-nnz(rightHalf)/numel(rightHalf))*100
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!