Contour not rendered for constant ZData

106 views (last 30 days)
Can anyone help and point me to write direction, I am trying to get the contour of 190 grayscale images but getting error. Code and error shown below.
for i=1:length(srcFile)
Warning: Contour not rendered for constant ZData
> In contour (line 51)
In imcontour (line 46)
In ContImages (line 8)
Error using imwrite (line 427)
Expected DATA to be nonempty.
Error in ContImages (line 10)

Accepted Answer

Walter Roberson
Walter Roberson on 19 Jul 2020
A) One of your images is constant value, such as if it is all black or all white.
B) You are reading in JPEG images. However, the overwhelming majority of .jpg files are RGB files even if they look gray. True grayscale .jpg files are possible but they are mostly only encountered as technical proofs that they can exist, or as part of "compression corpuses"... and occasionally they do show up in "real life" as the output of scientific devices (but rarely from cameras.) I would recommend that you account for the possibility that the image is not truly grayscale
if ndims(I) > 2; I = rgb2gray(I); end
The output of imcontour() is a contour matrix, not an image with the contours drawn in it. Contour matrices describe the contours, rather than being images. See . The result will be a 2 x something double precision matrix. You can technically imwrite() that, but you will not get anything useful as the result: it would be a 2 x whatever image that is nearly all white.
You can use tools such as or to extract coordinates from the contour matrix into an easier form, and you can then use Computer Vision toolbox insertShape() to draw the lines into an array that you can imwrite() .
Or you can let the contour draw to the display and getframe() -- less trouble, but it does require that a display be present (not suitable for batch processing.)

More Answers (0)


Find more on Modify Image Colors in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by