for a particular contour level,should the pixels have the same intensity
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I know that imcontour basically gives you a contour at a particular level.
My question is that the pixels that lie along that particular contou level r they al should have the same intensity and pixel values right.
for example in the below image(which shows the contour for an image at level 50),all pixels that lie along this contour should have their pixel intensity values somewhere close to 50 right?
l But,when I save this as jpg and run imtools on it I get this image where the pixel values along the contour are not havint heir intensity levels close to 50.

So to conclude
1.do all pixels along the contour (obtained at level X) have the same intensity values?
2 Could it be possible that when I saved the contour map as jpg,the values were changed and that's why I am getting the result shown in the second image.Also to view pixel values can I use impixelinfo or improfile?
Accepted Answer
Image Analyst
on 10 Oct 2021
No, all pixels along a closed contour do not have to have the same intensity. What if there just simply weren't any pixels of the contour level intensity? You can either leave the contour open, or if you close it, it will have to create a path in between values above the level and below the level.
8 Comments
sparsh garg
on 10 Oct 2021
Edited: sparsh garg
on 10 Oct 2021
so what does the term level specify here,I mean when i ran contourf/imcontour I got all these levels 40,60,80 etc.
Also you said
"or if you close it, it will have to create a path in between values above the level and below the level." does this imply that say for a contour at level 150,the pixel values will be close to 150 or will it be too far off like at one point the pixel could be 180 and at another point it could be 40?
Does this mean that along those contours you have pixels with intensity values close to that particular level.
Also,will improfile/impixelinfo help me in getting an insight into the pixel values along that contour.
PS i am aware that once you get a contour then looking into the pixel values there won't give you any info.
Walter Roberson
on 10 Oct 2021
Contour plots work on the assumption that the data available in the array is a sampling of a continuous function. That, for example, if a pixel with value 180 is beside a pixel of value 140, that there is some point between them that was value 150.
If you call contour() or contourf() and look at the first output, the coordinates returned are floating point values rather than integers. They represent continuous locations at which the algorithm figures that if you were to interpolate at that continuous point using the known values supplied in the discrete array, that the interpolated value would match the target level.
For example if the 180 was at x = 1 and the 140 was at x = 2, then it might calculate that at x = 1 3/4 that the value would have been 150. And that 1 3/4 would be the location returned in the contour matrix.
Now, that 1 3/4 would be in data units, not in pixels. Eventually those floating point data units need to be rendered to pixels. But pixels have integer locations. In this particular case if you happen to be able to allocate a multiple of 4 physical pixels per data unit, you could position the 1 3/4 exactly in one physical pixel... but you probably do not happen to have exactly a multiple of 4 physical pixels per data unit (and remember that with different arrays and different target levels, the location might be for example 1.45302116).
What do you do when you have an array location given in data units and that location does not match exactly into an integer location of pixels for display on the screen, or an integer location of pixels for storing into a file? Should you discard all locations that do not turn out as exact integers? Should you round them to the nearest underlying integer? Should you "turn on" the pixels that are passed through? Should you "turn on" the pixels that are passed through but with different intensities depending upon mathematically "how much" of the pixel is being occupied by the line ?
The floating point calculation of the locations where the value would interpolate to the target value (under the model of continuous linear surfaces) might be quite good, but pixels to draw in or array locations to turn on are discrete units.
sparsh garg
on 10 Oct 2021
Edited: sparsh garg
on 10 Oct 2021
ok thanks from what I can understand the process of mapping the data point to pixel is continuous to discrete which in the end might not give me a correct accurate resultAlso are there any ways of doing that,I mean isn't that what inverse warping does,tkae.Thanks for the explanation behind the contour.
Suppose you have the array
A = [180 * ones(8,4), 140 * ones(8,4)]
A = 8×8
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
180 180 180 180 140 140 140 140
and suppose that you ask to contour this at level 150.
Then, in your view, what would a "correct accurate result" be ?
sparsh garg
on 10 Oct 2021
Well for me the expected result would be like you click on the contour point which is say [x,y] and then that point will give me the pixel value of 150.But based on your explanation I don't think that is possible
for examplewhen I tried your example on matlab the resultant matrix is like this
[4.75 ,1;4,75 2;4.75 3;4.75 4 4.75 5 4.75 6 4.75 7 4.75 8]
since if we were to look for [4.74,1] into the A matrix it wouldn't show up; the value of 150 which as you said is an interpolated value between 180 and 140.
sparsh garg
on 4 Dec 2021
@Walter Roberson thanks for explaining the concept behind contourf ,is there any material out there which i can refer to like some lecture or pdf
Walter Roberson
on 5 Dec 2021
More Answers (0)
Categories
Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange
Products
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)