'How do I apply a colormap between minimum and maximum pixel values in image?

I have an 8-bit image ('Example_image.tif') that I would like to pseudo-color using custom RGB values from a .csv file ('Pseudocolor_sheet.csv'). The colormap is for pixel values between 0 and 255, however, I would like to apply the all the colors between the minimum and maximum pixel values present in the image.

Currently, the code yields a grayscale image with the various shades (black/grays/white) applied between the minimum/maximum pixel values. I'm trying to figure out how to apply the colors in this range. Thank you! Here's what I have so far:

clc;
clear;
close all;

%Choose an image
[filename,filepath] = uigetfile({'C:\Users\'},'Select Example Image','*');
ExampleImage = imread(strcat(filepath, filename));

%Determine minimum & maximum pixel values in image
Min = min(ExampleImage(:))
Min;
Max = max(ExampleImage(:))
Max;

%Display pseudo-colored image
cmap=csvread('pseudocolor_sheet.csv');
imshow(ExampleImage);
colormap(cmap);
colorbar;
caxis([Min, Max]);


Solution 1:[1]

As per the imshow documentation, to change the display range of colors, you can set the second argument.

imshow(ExampleImage, []);

or

imshow(ExampleImage, [Min Max]);

or

imshow(ExampleImage, 'DisplayRange', [Min Max]);

should do what you want.

Possible alternatives may include using imagesc or using something like imshow((ExampleImage - Min)/(Max-Min) * 255);.

Solution 2:[2]

I think I figured it out and may be related to my version of Matlab (2017a). I had to add "gca" in the 2nd line below:

imshow(ExampleImage, [Min Max]);
colormap(gca, cmap);
colorbar;

Solution 3:[3]

In the editor, in line 23 and in the Problems view the project build error Non-parseable POM .../pom.xml: in epilog non whitespace content is not allowed but got c (position: END_TAG seen ... is shown.

The error means you have or had the character c after </project> causing the pom.xml file become unreadable for Eclipse (non-parseable because of the invalid XML). The screenshot shows that you have already removed the character but did not save the change. So it seems you just missed hitting Ctrl+S to save the pom.xml containing nothing or only whitespace after </project>.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 magnesium
Solution 2 Peter
Solution 3