how to add a custom colormap to 16 bit grayscale image without using imshow

7 visualizaciones (últimos 30 días)
I have a 16 bit image and want to create a colormap based on pixel intensities.
I am interested in a narrow band betwen 0 and 6000 pixel intensity, and want to have a colormap on the image for further analysis on the picture such as adding annotations etc.
The only way I found that works, is by using imshow. The problem is that I don't want to display the image, I want to do further analysis.
Is there a way to do what imshow does, without actually showing the image?
imshow(image, 'DisplayRange',[0 6000],'Colormap',customColormap);

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Ag. de 2020
Try this. I made a 400 row by 600 column uint16 image with values from 1 to 6000. Then I took a range of values from 3000 to 3805 and pseudocolored them with the "jet" colormap. I used 3805 just to make it bigger so you can see it in the image, but feel free to use 3005 as long as you have enough pixels in that range to see a difference. Of course you could colorize outside that range with a different colormap if you want or even a colormap that's all black to blacken everything outside the desired range. Let me know if this meets your needs.
% Create sample data.
data = linspace(1, 6000, 400*600);
data = reshape(uint16(data), 400, 600);
% Show image in it's original gray scale.
subplot(2, 1, 1);
imshow(data, []);
colormap(gray(256));
colorbar;
title('6000 gray levels in gray scale', 'FontSize', 15);
% Show image where a specified range is in pseudocolor.
subplot(2, 1, 2);
cmap = gray(6000);
row1 = 3000; % Whatever.
row2 = 3805; % or 3005 or whatever you want.
% Make the jet colormap with the proper number of rows.
cmap2 = imresize(jet(row2-row1+1), [row2-row1+1, 3]);
% Paste that over the appropriate rows of the gray scale colormap.
cmap(row1:row2, :) = cmap2;
imshow(data, [], 'Colormap', cmap);
colorbar;
caption = sprintf('6000 gray levels with %d - %d in pseudocolor', row1, row2);
title(caption, 'FontSize', 15);
  3 comentarios
Walter Roberson
Walter Roberson el 20 de Ag. de 2020
rgb = ind2rgb(data, cmap);
title_x = 100; title_y = 350;
rgbtitled = insertText(rgb, [title_x, title_y], 'The rain in Spain');
Image Analyst
Image Analyst el 20 de Ag. de 2020
insertText() burns the text into the image, changing the pixel values. text() places the text into the overlay, not altering the pixel values. Use whichever you want.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Ag. de 2020
Yes, you can use ind2rgb() to make the rgb image. Then you don't have to display it if you don't want to, or you could display it with imagesc() or image() instead of imshow().
  8 comentarios
John Doe
John Doe el 18 de Ag. de 2020
"... Is the idea that you want a colormap to be applied selectively to values in the range 0 to 6000, and that all other values are to be left as-is ?"
I see there's some confusion about exactly what I'm trying to achieve. but essentially that is what I want to achieve, except there's no other values.
my picture grayscale 16 bit picture only has pixel intensites between 0 and 6000. No need to rescale.
I want to visualize the difference between these using a colormap that can show difference between, for example, 3000 and 3005, and afterwards add text to the colormap using insertText.
I found an alterative to imshow but it does not help much since imagesc also displays the image and i'm unable to use insertText on this
colormap(PlusMinus);
chart = imagesc(BlurJ);
ax = gca;
ax.CLim = [0 6000];
axis off
Now I want to use insertText but to be honest have no idea what exactly to annotate. it gives me an error when i try gca (Expected input number 1, I, to be one of these types:uint8, uint16, int16, double, single Instead its type was matlab.graphics.axis.Axes.), and adding the annotation before the colormap seem to change values.
colormap(PlusMinus);
chart = imagesc(BlurJ);
ax = gca;
ax.CLim = [0 6000];
insertText(gca,[20 1100],'hallo','FontSize',10);
axis off
when I try using ind2rgb() it does not apply colormap correctly. it seems to assume most of the intensity is out of range.
BlurJ = ind2rgb(BlurJ,PlusMinus);
chart = image(BlurJ);
ax = gca;
ax.CLim = [0 6000];
axis off
Walter Roberson
Walter Roberson el 19 de Ag. de 2020
I want to visualize the difference between these using a colormap that can show difference between, for example, 3000 and 3005, and afterwards add text to the colormap using insertText.
Generally speaking, you can use ind2rgb() or other forms of lookup table in order to create a color array representing the data. Then you can use Computer Vision insertText() to draw text into that array if desired.
The question at this time would be how you want to represent the color scheme.
See for example https://www.mathworks.com/matlabcentral/fileexchange/69470-custom-colormap which permits you to define relative positions (on the range 0 to 1) and corresponding colors, and will interpolate between them to the number of locations you specify. If you specified 6001 then you could use ind2rgb() with the map you had created. Otherwise you could use three interp1 calls.
Indeed, if you have a list of positions and rgb components and are willing to interpolate between them, then you can use three interp1() calls directly without using the FEX contribution. The first parameter would be the positions of change; the second parameter would be the color component value at those locations; the third parameter would be the image value.

Iniciar sesión para comentar.

Categorías

Más información sobre White en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by