MATLAB Answers

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

3 views (last 30 days)
Sparsh Garg
Sparsh Garg on 28 Jul 2021
Answered: DGM on 29 Jul 2021
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 Comments
Sparsh Garg
Sparsh Garg on 29 Jul 2021
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.

Sign in to comment.

Answers (1)

DGM
DGM on 29 Jul 2021
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!