How should I go about assigning a color to a range of values in a 1800x1200 array?

3 views (last 30 days)
I'm trying to analyze a grayscale image and use the flux values to create a map of the flux over the entire image. I have calculated the flux values for the entire image, but now I need to create a photo that shows the flux as a color based on the value. I have used an if loop to assign colors to a range of flux values, now I just need a way to parse through the array and assign the colors to the pixels. Any suggestions would be super helpful.
  2 Comments
DGM
DGM on 25 Mar 2024
Provide an example of the data you're working with and what you're trying to do. This sounds like something that could potentially be much simpler than what you're doing, but I can't really be sure whether you're trying to make a complete pseudocolor image or whether you're trying to create a composite image with an overlay in a particular range.
Jadyn
Jadyn on 25 Mar 2024
I'm trying to take this photo and correlate measured values to the graypoint of an image. I'm trying to change the image from grayscale to a completely colored image that will show the lowest and highest values. I'm trying to create a pseudocolor image I believe.

Sign in to comment.

Answers (1)

DGM
DGM on 25 Mar 2024
Edited: DGM on 25 Mar 2024
If you're just trying to make the whole thing pseudocolor based on known limiting values (e.g. the extrema of the image data), then you should be able to use either imshow() or imagesc() to visualize it if you want to plot it.
inpict = imread('IMG_7233(lamp1).JPG');
inpict = im2gray(inpict);
% the image data spans the dynamic range of uint8
% if you want to choose other gray levels to use as your reference
% you would choose them here
inrange = imrange(inpict); % gray value
% let's say that those graylevel values correspond to
% measured values in the range of 50-75 units
% (idk what your units are so i'm just making something up)
outrange = [50 75]; % measured value
% rescale the image from graylevel units to measured units
datapict = rescale(inpict,outrange(1),outrange(2),...
'inputmin',inrange(1),'inputmax',inrange(2));
% display it using imshow()
imshow(datapict,outrange)
colormap(parula(256)) % set the colormap
colorbar % add a colorbar
... or if you want to get the pseudocolor image and save it directly, you can do it this way in order to avoid taking a screenshot.
% if all you need is the image without the colorbar
inpict = imread('IMG_7233(lamp1).JPG');
inpict = im2gray(inpict);
% pick the input levels as before
inrange = imrange(inpict); % gray value
% generate the image given the desired colortable and limits
outpict = gray2pcolor(inpict,parula(256),inrange,'cdscale');
% display the image
imshow(outpict)
% save the image
imwrite(outpict,'myfile.png')
The functions imrange() and gray2pcolor() are attached.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!