Adjusting color limits on displayed color images

When displaying a color image is it possible to set the limits of the cData. The below dcoumentation states that if a double is given then the limits range from 0 to 1 with different values for int8 etc.
Is it possible to change what these limits are, ideally with different values for each channel. Currently my solution is to scale the origional data before senging it to image(), but this is slow to do each time the user wants to adjust these scale values to highlight different parts of the data. It also prevents tools like impixelinfo from giving correct values. Also if there are any other features that are plotted such as boxes then these also need to be redone. Zoom ranges and everything else also need to be preserved. This all becomes a big hassle and affects performance if the user is regulary changing the intensity scales.
How are these limits set? CLim seems to have no effect, neither do the colormaps.
Is it possible to set the black and white values of a displayed image through some undocumented feature?
Cheers Alaster
  • 3-D array of RGB triplets — This format defines true color image data using RGB triplet values. Each RGB triplet defines a color for one pixel of the image. An RGB triplet is a three-element vector that specifies the intensities of the red, green, and blue components of the color. The first page of the 3-D array contains the red components, the second page contains the green components, and the third page contains the blue components. Since the image uses true colors instead of colormap colors, the CDataMapping property has no effect.
  • If CData is of type double, then an RGB triplet value of [0 0 0] corresponds to black and [1 1 1] corresponds to white.
  • If CData is an integer type, then the image uses the full range of data to determine the color. For example, if CData is of type uint8, then [0 0 0] corresponds to black and [255 255 255] corresponds to white. If CData is of type int8, then [-128 -128 -128] corresponds to black and [127 127 127] corresponds to white.
  • If CData is of type logical, then [0 0 0] corresponds to black and [1 1 1] corresponds to white.

Antworten (1)

Image Analyst
Image Analyst am 26 Aug. 2024

0 Stimmen

What data type do you have for your indexed image? If it's double, it should be in the range 0-1, and if it's uint8 it should be in the range 0-255. Your Nx3 colormap matrix should always be in the range 0-1 no matter what type of variable your image (CData) is.
If you have a double not within the range 0-1 then you will either have to convert it to the range 0-1 with (I believe) mat2gray. If it's integer outside of the range 0-255, like it's uint16 in the range 0-65535, then it should also work.
Once your image is put into ax axes with imshow or image, then you should be able to quickly change and apply a new colormap very quickly. There is no need to transform the image every time once it's been put into the axes control.
clim does not affect the colormap but what it does is to say what value of your data should use upper and lower rows of your colormap. For example if your colormap goes from black to red, and your data goes from 0.3 to 0.7, then you can use clim to say that you want everything from 0 to 0.5 to be black, and everything above 0.6 to be red, and the range 0.5 to 0.6 to be what your colormap is. For example if you have 64 indexed colors, the 64 colors would apply to pixels in the range 0.5-0.6 and everything less than 0.5 would use the color in the first row of the colormap array and everything above 0.6 would appear as the color in the 64th row of the colormap matrix. Using colormap to apply a new colormap matrix, or using clim to change the limits should be virtually instant.

5 Kommentare

DGM
DGM am 26 Aug. 2024
Bearbeitet: DGM am 26 Aug. 2024
The values of an indexed image will be within [1 N] for a color table of Nx3. An integer indexed image with have values within [0 N-1]. It's a literal array of row indices. This is what image() is for.
Scaled color representations can be in any range.The CDataMapping property controls whether an image is represented in scaled color or direct (indexed) color. This is the difference between image() and imagesc(). For imshow(), all standard grayscale images are treated as scaled color with class-dependent default clim().
Standard truecolor images will be within [0 1] for float or the full range if integer. Clim() doesn't affect truecolor or direct colormapped (indexed color) representations.
Hi,
Prehaps I was not clear in my question. I am aware how clim and colormap work when using a single channel data.
When displaying single channel data everything works fine. I can use clim to set the black value and the white value, use3 whatever colormap I want and everything works great. It doesn't matter if I'm using a double that is out site the range of 0 to 1, just set the clim and everything is great.
If I want to highlight a certin dim feature, easy, I just reduce the white value in clim.
TThis is the functionality I want to have when I am displaying 3 channel data. All of a sudden clim has no effect. If I zoom in on a dull feature and I want to adjust the brightness then have to rescale and reset the cdata being displayed.
What I'm after is something that gives me the functionality of clim has on single channel data but have it work for 3 channel data, ideally being able to scale each colour channel independantly.
DGM
DGM am 26 Aug. 2024
Yeah I didn't notice that detail until I got back from the shop. For truecolor inputs, clim() doesn't apply. Image(), imagesc() and imshow() will all display a MxNx3 image with respect to its class-dependent limits, regardless of clim().
I'm pretty sure that if you want to adjust the channels independently for display purposes, you'll need to do that rescaling directly on the image data.
Like DGM said, clim() does not apply for true color, three channel, RGB images. A colormap is only for turning a gray scale into a color, not for turning one RGB color into a different RGB color.
If you want to highlight something, like make it a different color or superimpose a colored overlay on top of it, you can segment the region you want to highlight by whatever means you need to (so that you now have a binary image, mask), and then use imoverlay or labeloverlay to apply that segmented mask to the image.
Consider using rgb2ind to convert to an indexed image; after that, adjust the colormap dynamically as necessary.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2024a

Gefragt:

am 26 Aug. 2024

Kommentiert:

am 26 Aug. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by