Change pixel color and intensity independently in an image

8 ビュー (過去 30 日間)
Lucile M
Lucile M 2020 年 6 月 25 日
コメント済み: Image Analyst 2020 年 7 月 14 日
I have a matrix (ratioImage) of class double that I am plotting as a color image. So I get an image with different colors indicating the different values of pixels in my matrix using imshow and colormap('jet'). Now, I would like to vary the pixel intensity (brightness) according to the values of the pixels contained in another matrix (Nphotons). I want to keep the same colors indicating the values in ratioImage, but I want to adjust the brightness of each pixel according to the values in Nphotons. Is it possible to do that with Matlab? Any clue on how to start this?
Thank you!

回答 (2 件)

Johannes Fischer
Johannes Fischer 2020 年 6 月 25 日
Here is how i would try to do it:
% First, you need to get the image that you see as an RGB-matrix. If your
% ratioImage is an NxM matrix, you want a NxMx3 matrix where the last
% diemsion stores the three color channels red, green and blue.
rgbMat = ind2rgb(ratioImage, jet(256));
% in order to change the brightness, you need to convert these values into
% another color-space, L*a*b. The L*a*b color-space does not have 3 color
% channels (like RGB) but one channel for Lightness and two for color.
labMat = rgb2lab(rgbMat);
% Now you can change the values in the first channel of labMat to adjust
% the brightness.
labMat(:, :, 1) =
% after you are done, convert back to RGB and display
rgbMat = lab2rgb(labMat);
On a different note:
Many people object to the use of the colormap jet. It produces very colorful images, but at the cost accurate interpretation of your data, because the contrast is not uniform. Hence, a couple of years ago matlab introduced a new (default) colormap 'parula'. Steve Eddins wrote about their rationale in these blog posts:
But since you additionally change the brighntess depending on values in another matrix, these considerations are maybe not necessary your case.
  1 件のコメント
Lucile M
Lucile M 2020 年 7 月 14 日
Thank you for your answer. I understand the point but it does not really do what I need. The values in the matrix are completely modified when converting back to RBG, and when plotting the pattern does not tell anything anymore. It is still helpful information though! I'll try a bit further and come back here if I succeed at some point.


Image Analyst
Image Analyst 2020 年 6 月 25 日
If you use caxis() you can basically "pin" the ends of your jet colormap to whatever values you want. So if your original image range was 0-2 and you had 0 blue and 2 be yellow because you used jet(256), and then you wanted to raise the values so that now your range is 1-3 but you still wanted 2 to be yellow, you could set caxis([0,3]) after each time you called imshow() or image(). If you do that, 0 would be blue, 2 would be yellow, and 3 would be red regardless of the values present in the image. If you don't then the colormap will adjust automatically so that the min intensity value (regardless of its absolute value) will be blue and the max intensity value (regardless of its absolute value) will be red and the images would look the same even though you raised the values of the image pixels.
  2 件のコメント
Lucile M
Lucile M 2020 年 7 月 14 日
Thank you for this tip! I don't want to play on colors though, but on intensities (which I'm not sure is possible in matlab)
Image Analyst
Image Analyst 2020 年 7 月 14 日
Instead of jet(), you can use a colormap called gray() that has no colors, just grayscale intensities.



Help Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by