Is my bar graph accurately graphing what I ask?

조회 수: 1 (최근 30일)
Neo
Neo 2023년 2월 2일
댓글: Image Analyst 2023년 2월 3일
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