Colorscale Conversion Gray to jet
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I save a 2d Matrix visualized in colormap 'jet'. When this is saved as an image, it is saved as RGB image.
Now, I want to convert the RGB image to gray. If I do RGB to gray, the image recovered is inaccurate.
How can I solve this?
Appreciate any response.
Thank you!
0 commentaires
Réponses (1)
Bhanu Prakash
le 19 Oct 2023
Hi Rashmi,
As per my understanding, the recovered image using the ‘rgb2gray’ function is not accurate and you want to improve its accuracy.
If you already have the RGB image, then you can load the image and the colormap using the ‘imread’ and ‘jet’ functions respectively as shown below:
% Load the RGB image
rgb_img = imread('your_rgb_image.jpg');
% Load the colormap 'jet'
cmap = jet(256);
To convert an RGB image to grey image, the colormap values are to be in the range [0,1]. You can normalize the colormap values to the required range in the following manner:
% Normalize the colormap to the range [0, 1]
cmap_norm = cmap / max(cmap(:));
To preserve the image details during conversion, the RGB image is converted to an inverted image and then to a gray image using the ‘rgb2ind’ and ‘ind2gray’ functions as shown below:
% Convert the RGB image to indexed image using the colormap 'jet'
indexed_img = rgb2ind(rgb_img, cmap);
% Convert the indexed image to grayscale using the normalized grayscale colormap
gray_img = ind2gray(indexed_img, cmap_norm);
The above approach provides a better accuracy of the recovered image compared to the approach using ‘rgb2gray’ function.
For more information on the above-mentioned functions, refer to the following documentation:
1.For ‘imread’ function:
2.For ‘jet’ function:
3.For ‘rgb2ind’ function:
4.For ‘ind2gray’ function:
0 commentaires
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!