How to apply a filter to an image to scale the saturation?

I am trying to represent two distinct variables in a single figure by denoting one of the variables with hue and the other with saturation.
See below for an example from the literature:
The color bar contains two variables: phase and intensity. Color hue represents phase while color saturation represents the intensity. (Note: the authors should have written "intensity" instead of "amplitude")
To achieve this figure, I have one matrix that represents intensity
and another that represents phase
I would like to scale the saturation of each point in the phase matrix by the corresponding value of the intensity matrix. For example, there are regions in the intensity matrix where there is 0 signal. The saturation of the corresponding indices in the phase matrix ought to be multiplied by 0 in this case. On the other hand, there are other regions in the intensity matrix where the signal is brightest, i.e. 1. The saturation of the corresponding indices in the phase matrix ought to be unchanged in this case. To summarize the question, I would like to use a matrix of values between 0 and 1 as a filter to scale the saturation of a different matrix with the same dimensions. In this case, the matrix of values between 0 and 1 is the intensity matrix and the matrix-to-be-scaled is the phase matrix.

Answers (2)

Use hsv2rgb where you construct the hsv image with your matrices:
hsvImage = cat(3, hueImage, saturationImage, intensityImage);
rgbImage = hsv2rgb(hsvImage);
See how that works. If it doesn't look good, try making the intensity image range from 0-100
intensityImage = 100 * mat2gray(intensityImage);
before putting into hsvImage. If RGB image is in the range 0-255 then it must be cast to uint8 before displaying. If it's in the range 0-1 then you should be able to use imshow on it directly.

3 Comments

Thanks for taking the time to look at my question, Image Analyst.
In order to implement your approach, I first converted the phase matrix into an image using code I copied from this thread:
colormap('spring');
C = colormap;
L = size(C,1);
Gs = round(interp1(linspace(min(phasemat(:)),max(phasemat(:)),L),1:L,phasemat));
phaseIm = reshape(C(Gs,:),[size(Gs) 3]);
where phasemat is the phase matrix attached in my original post.
Then I used your reply from an earlier post to extract the hue and saturation images. For the intensity image, I first tried the intensity matrix shown in my original post where the values range from 0-1 and I obtained this result
(Note: I used imagesc to generate that image so the vertical axis is flipped in comparison to the contour plots from my original post.) It seems like this procedure correctly imprinted the intensity image on the hue and saturation images from the phase matrix. However, I don't understand why there are black regions in the spectrum. These regions with low intensity should be colorless or white as opposed to black or dark green.
Next I tried your suggestion to scale the intensity image from 0-100 and I obtained this result
(Note: both RGB images were in the range 0-1 so I did not cast to uint8 before displaying.) Unfortunately neither result seems correct.
I appreciate your reading this long post. Please let me know if you spotted a mistake in my analysis or if you have additional suggestions.
I'm a little unsure what you want. If the intensity is low, it will be black. If you don't want it black then set intensity equal to one minus intensity. If you can, mock up what you'd like and show that, and attach your images for phase, hue, saturation, and intensity.
Instead of replying to your comment, I accidentally added a new answer. Please see below for a response to your comment.

Sign in to comment.

I want the processed phase image to be white in regions where the intensity is low. And in regions where the intensity is high, the processed phase image should retain the color of the original phase image.
For example, look below for black arrows that indicate the brightest regions of the intensity image.
I want the processed phase image to be effectively unchanged in this area of the spectrum. In contrast, the blue arrows indicate the regions of the spectrum with very low intensity. Here I want the processed phase image to be white.
I made a poor quality mock-up using Illustrator. See below.
The phase, hue, saturation, and intensity images are attached as a mat file.

Asked:

on 11 May 2018

Commented:

on 16 May 2018

Community Treasure Hunt

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

Start Hunting!