MATLAB: show a grayscale color panel of an image in a shape containing an RGB image

Suppose we have two images:

1) RGB image:

% initialize RGB image: rgbIm = zeros(100, 100, 3); rgbIm(20:80, 20:80, 1) = 1; 

2) Grayscale image:

 % initialize grayscale image: grayIm = zeros(100); grayIm(20:80, 20:80) = 1; 

Show both of them:

 figure, imshow(rgbIm), colormap('jet'), colorbar; figure, imshow(grayIm), colormap('jet'), colorbar; 

As we can see, the color line in the second figure (i.e., the image in grayscale) has a general meaning. On the other hand, I cannot understand the information indicated in the color scale in the first figure.

What I would like to achieve is to display the color frame of the image in grayscale in the image corresponding to the RGB image .

This may not seem to make sense, but this is just a very minimal example that I just did to show what I would like to do in a larger project.

Any thoughts?

Thank you very much:)

EDIT1: Let me explain why I need it

Suppose I calculated some physiological parameters for a single slice of an MRI scan in certain areas of interest:

parametric image

Now I want to overlay these parameters on top of the original fragment, and for this I create one RGB image:

superimposition on the original image

The color palette does not make sense, and that is why I would like to display a color palette corresponding to the parametric image in the RGB image (i.e. the overlay image).

Any ideas?

Thank you for your attention.

0
source share
2 answers

(Answering my own question so that I can hope to help someone in the future)

I just did what I intended with the help of the above answer and a post from Steve Eddins Blog . Here's how:

 baseImage = baseImage/(max(baseImage(:))); % normalize base (anatomical) image rgbSlice = baseImage(:,:,[1 1 1]); % converting to RGB (ignore colormaps) imshow(parameterROIImage, []); % show parametric image colormap('jet'); % apply colormap hold on; h = imshow(rgbSlice); % superimpose anatomical image set(h, 'AlphaData', ~bwROIlocations); % make pixels in the ROI transparent colorbar; 

where parameterROIImage :

enter image description here

bwROIlocations is a logical matrix containing ROI pixels:

enter image description here

Final result:

enter image description here

Thanks for helping Shai.

+1
source

I still think that what you ask does not make sense.
Let me explain:
What is colorbar ? Colorbar is a representation of a function (display) from gray (scalar) to color. Using jet , in your example you match 0 with blue and from 1 to red.
By requesting a colorbar for an RGB image, you are actually requesting a mapping from an RGB trigger to an RGB color - this mapping is an identification mapping! you don’t need a colorbar to see this display, each pixel represents it!

EDIT

After viewing the edited question, I will slightly revise my answer:
Since both the MRI signal and any physiological parameters that you have calculated do not make sense in the RGB space, you have two one-dimensional displays:
1. MRI signal at each voxel level to gray level ("gray" color)
2. Physiological measure on each voxel to β€œink” color

What I usually do in this case is to convert a 2D MRI fragment to a gray RGB image, just reproducing it in a third size

 rgbSlice = twoDSlice(:,:,[1 1 1]); 

Now show the images on top of each other

 figure; imshow( rgbSlice ); hold on; h = imshow( physiologicalParams ); colormap jet; set(h, 'AlphaData', .5 ); colorbar 

You may need to play with the color display of the axes using caxis or clim to get it right.

+1
source

Source: https://habr.com/ru/post/1481235/


All Articles