negative values of pixels in aimage

34 views (last 30 days)
hi..
Can a image contain negative value of pixels ?
what does negative value of pixels in a image mean?

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2012
Edited: Walter Roberson on 5 Mar 2016
Yes, as a generality, images can contain pixels with negative values.
If I recall correctly, if you look at the diagrams of color representation as perceived by the human eye, and you look at how they define RGB coordinates, then there are some colors that humans can perceive that would have to be modeled as negative coordinates. RGB and the other color spaces in common use in image file formats, are approximations of what we can really see, and since approximations are imperfect, some colors visible to humans (at least under perfect conditions) fall outside the models.
Ask yourself this: what color is infrared in RGB coordinates? It doesn't fit. But you might have taken an image with a camera that is sensitive to infrared as well as to visible optics, so you might want to deal in negative coordinates.
Pixel values are interpreted, part of a mathematical model, and need not represent real measurements in physics -- or might represent measurements whose zero point was originally determined before all oddities were known, leading to some negative readings.
Example: if you were taking astronomical pictures, it might make sense in some contexts to use stars' apparent magnitude as the pixel values. If one excludes the Sun and planets, that still leaves a small number of stars (about half a dozen at most) that would have negative values.
  5 Comments
Aarach Sap
Aarach Sap on 19 Oct 2016
The image file formats that I know of that support negative values are DICOM (use dicomwrite() for that), and TIFF (you need to use the TIFF class and special settings to be able to store negative values.)
I have input image as Tiff image(RGB). I convert to YDbDr then I perform some operation on each channel and the results in one channel is negative. Now I want to convert Ydbdr into RGB. Then want to write the image on matlab and display in RGB space. But my result appears pink and I display on 'uint8'. how to deal with negative values in tiff? what is the setting?
Walter Roberson
Walter Roberson on 19 Oct 2016
Edited: Walter Roberson on 19 Oct 2016
I had not heard of YDbDr before; it appears to be https://en.wikipedia.org/wiki/YDbDr. One routine that handles the conversion is https://github.com/petercorke/machinevision-toolbox-matlab/blob/master/colorspace.m
To store floating point values in TIFF see:
It appears that there is no good PhotometricInterpretation for uninterpreted data; MinIsBlack looks like it might be the common for this case, even though that is entirely misleading for the situation, and I can see the potential for problems with values that happen to be 0 perhaps interpreted as black. The underlying TIFF tag appears to be 1 = BlackIsZero which LibTiff seems to call PHOTOMETRIC_MINISBLACK so I am not at all sure that MinIsBlack is going to work for this. But I cannot see anything better at the moment. DNG has 34892 = LinearRaw and perhaps that would make the most sense.... though you would have a difficult time finding software that could interpret it. I thought for a moment that perhaps PHOTOMETRIC_SEPARATED ("usually CMYK") would be the approach but I see in other postings that separated requires that the data channels be percentage of inks, which is not appropriate here.
... but perhaps all of that is irrelevant if you are not trying to write out the YDrDb as a TIFF file. If you are just holding it in memory or are saving it as .mat or something like that, then you do not care how TIFF represents data that does not match one of its color specifications.
"Now I want to convert Ydbdr into RGB"
Try the routine from the PeterCorke toolbox. Or you could pull down https://www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!