Can I save an image with different colormap? (Readable by Matlab)
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Sailesh Kalyanapu
2022-5-18
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 个评论
DGM
2022-5-18
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!