Change pixel color and intensity independently in an image
8 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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);
imshow(rgbMat)
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.
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 个评论
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 Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!