how to get x,y pixel values of each object separately in labeled watershed image?

조회 수: 1 (최근 30일)
Hello all. I have extracted the tomato using watershed and labeled them. Now I want to know x, y, RGB, all values regarding this. I can get values for all objects in image but I want to get the values of each object in the image separately.
i want pixel values of each fruit in image separately with its color, because i want to map these values on point cloud, so that i can recognize that which fruit is which one. How I can do it? Kindly guide me as soon as you all can. Thanks.
See attached image: .

답변 (1개)

Image Analyst
Image Analyst 2018년 12월 19일
watershed() gives you the labeled image, L. To get the x, y, R, G, B values, extract each label one at a time.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
numRegions = max(L);
for k = 1 : numRegions
thisRegion = ismember(L, k);
[y, x] = find(thisRegion);
redValues = redChannel(thisRegion);
greenValues = greenChannel(thisRegion);
blueValues = blueChannel(thisRegion);
end
  댓글 수: 15
Image Analyst
Image Analyst 2018년 12월 25일
편집: Image Analyst 2018년 12월 25일
rgbImage is whatever you called your original RGB image. Maybe you called it (unfortunately) "I" or maybe you called it img or some other name - I don't know what you called it.
If you put your watershed() output into a variable called "Lrgb" then use that instead of "L" of course.
A lot of times you'll see people upload code here, and of course they have to pick names for their variables. It's assumed that the poster will know to replace those names with their own names if they want them to be different.
Muhammad Hammad Malik
Muhammad Hammad Malik 2019년 1월 7일
in watershed image you can see it contains four objects of different colors and i need to get x,y pixel values of each color.did you get it sir?thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by