given a contour returned by contourf,how to display the pixel values within a region

7 次查看(过去 30 天)
So,lets say I run contourf on an image ,and I get the contour for a particular level
say I is the image and level is [55,55].
Then running contourf(I,level) gives me the contour for level 55.
Now I would like to observe the pixel values within a certain region just as imtool does,is there a way for doing this?
Any help will be appreciated.
  4 个评论
Sparsh Garg
Sparsh Garg 2021-7-29
Update: seems I have found a rough soln
first I use imcontour to get the contour of a level X,I save that image then run imtool on it to get a understanding of the pixel values for that contour.
Now the problem here is that if I wanted to look at the pixel values for contour level Y and X at the same time,I don't think I can do that .Or can I.
Contour at level 55
contour at another level 50
Pixel values for contour 55
Pixel value for contour 50
So is there a way in which I can show the two figures on one figure ,i tried doing hold on but it doesn't work.
Bottom line :I am able to get pixel value for contour using a combination of imcontour and imtool,but I would like to display all the contour pixel values together.
Sparsh Garg
Sparsh Garg 2021-7-29
thanks for the input,but this is what I was asked to do,and apparently the guy above me seems satisified with what I gave him.
Don't beat the messenger.

请先登录,再进行评论。

回答(1 个)

DGM
DGM 2021-7-29
Why are you trying to get the pixel value of a contour map? The pixel values of the contour map don't tell you anything about the image -- the shape of the contour does. What's worse is you're looking at the pixel values in a map that looks like it's been damaged by saving it as a JPG. This is meaningless information.
This is one attempt:
testpict = im2uint8(mat2gray(peaks(500))); % make a test image
imshow(im2double(testpict)); hold on % draw image
contour(testpict,[55,55]); % draw contour map over image
The reason that the image is cast as double in the imshow() call is so that the pixel values are comparable to those used by contour(); otherwise, the contour lines won't be visible. Can the image be displayed in uint8 format with the contour overlay so that the datatip values are in uint8 range? I don't know. Maybe.
You can also just avoid the ambiguity of using a single-level contour map and just select a specific region and mask it off explicitly.
m = testpict <= 55;
maskedpict = im2uint8(im2double(testpict).*m);
imshow(maskedpict);
Either way, you can get the values of the image pixels using impixelinfo() or a datatip, as has been suggested already.
impixelinfo % mouse over for current pixel coordinates and value

Community Treasure Hunt

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

Start Hunting!

Translated by