Is my bar graph accurately graphing what I ask?

1 次查看(过去 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 #')

采纳的回答

Image Analyst
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 个评论
Neo
Neo 2023-2-3
So i can understand your though process better, why did you plot them seperatley?
Image Analyst
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 CenterFile Exchange 中查找有关 Deep Learning for Image Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by