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

10 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Sailesh Kalyanapu
Sailesh Kalyanapu il 18 Mag 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 Commento
DGM
DGM il 18 Mag 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)

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by