Effacer les filtres
Effacer les filtres

Can I save an image with different colormap? (Readable by Matlab)

12 vues (au cours des 30 derniers jours)
Martino Riccardi
Martino Riccardi le 14 Mai 2022
Commenté : DGM le 18 Mai 2022
I used the command "imread" to get a matrix A of the image and its colormap.
I inverted the colormap with:
Icmap=colormap(flipud(cmap));
I want to apply the inverted map to an image B and save the result.
Is there a way to save the image B taking into account the new colormap, such that it's readable by the command "imread"?
If I use the command "imwrite":
imwrite(B,Icmap,"image_name.png")
I get an image in my folder which represents what I want (if I open it OUTSIDE Matlab), but the command "imread" gives me the original image B as a matrix.
Thank you, in any case

Réponse acceptée

Sailesh Kalyanapu
Sailesh Kalyanapu le 18 Mai 2022
It is my understanding that you are looking to save an image with a different colormap and later read it using the function 'imread()
It is possible to do so using the ind2rgb() function.
Please add the following command in your code before calling the ‘imwrite()’ function and later use the imread() to get the true RGB format matrix
>> [X,cmap] = imread(filename);
>> Icmap = colormap(flipud(cmap));
>> Y = ind2rgb(X,Icmap);
>> imwrite(Y,filename1);
>> X_required = imread(filename1);
Please refer to the following link to a documentation for more information about ind2rgb() function:
  1 commentaire
DGM
DGM le 18 Mai 2022
Why convert to RGB? PNG supports indexed images.
[inpict map0] = imread('canoe.tif');
map1 = 1-map0; % invert map
imwrite(inpict,map1,'invertedcanoe.png') % save
[newpict newmap] = imread('invertedcanoe.png'); % read
imshow(newpict,newmap)
Note to OP: I think the obvious interpretation of "invert" is the unit complement of an image, so the inverse of cmap is 1-cmap. Flipping the map might be equivalent if the map is a simple linear RGB sweep. It all depends on what you actually want to happen. Note that in this case, flipping the map doesn't turn out so well.
[inpict map0] = imread('canoe.tif');
map1 = flipud(map0); % flip map
imwrite(inpict,map1,'invertedcanoe.png') % save
[newpict newmap] = imread('invertedcanoe.png'); % read
imshow(newpict,newmap)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by