Is my bar graph accurately graphing what I ask?
2 次查看(过去 30 天)
显示 更早的评论
i have an image which i have divided into 12 regions. I have made a code that I think counts the number of green dots in that image and plots them in a bar graph as function of the region in the image. is the code doing what i expect it to do? please correct or confirm.
First, the code converts the image (premask) into a gray image then applies a mask (screenshot). now that the mask is applied i want to count those specks as a function of their region because i want to see how the specks fluctate by number across the image in its differnt regions.
% count the graylevel specks and plot as a function of the region number (the once green specks).
greenspots = (g<255);
numberofgreenspots = numel(grayImage);
[pixelCounts, grayLevels] = imhist(grayImage);
%meanGL(k) = mean(grayImage(masksinusoid));
figure
bar(numberofgreenspots, 1:length(endingColumns));
grid on;
title('counting')
xlabel('green speck #')
ylabel('region #')
0 个评论
采纳的回答
Image Analyst
2023-2-3
No, you'd need to do this
% count the graylevel specks and plot as a function of the region number (the once green specks).
for k = 1 : whatever
greenSpotMask = g < 255; % g is the image of just this strip only.
% Count pixels.
areaOfGreenSpots(k) = nnz(greenSpotMask)
% Count number of contiguous regions.
[~, numberOfGreenSpots(k)] = bwlabel(greenSpotMask);
% Display histogram of strip.
[pixelCounts, grayLevels] = imhist(g);
%meanGL(k) = mean(grayImage(masksinusoid));
end
figure
bar(numberOfGreenSpots);
grid on;
title('Counting of Green Spots per Strip Region')
xlabel('Region #')
ylabel('Number of green spots in the region')
9 个评论
Image Analyst
2023-2-3
They represent totally different things and have different ranges. The number of pixels might be in the hundreds of thousands and the number might be a few dozen or hundred. You'd need at least 2 y axes, using yyaxis(), to plot them on the same plot. Like I said, the number of spots, like what you names the variable at the beginning, is most likely not what you want. You probably want the number of pixels (which is the area).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!