How to Store this attached rgbimage with a colormap. I tried the following code but could not write the image with colormap.

2 ビュー (過去 30 日間)
I tried the following code to write the image with map. But again the colormap is null.
[img, map] = imread('1.jpg');
map = []
>> [indimg,map1] = rgb2ind(img,32);
>> imwrite(indimg,map1,'new.jpg');
>> [img, map] = imread('new.jpg');
>> map
map = []

採用された回答

Subhadeep Koley
Subhadeep Koley 2020 年 3 月 1 日
Your are writing the image in JPEG format and imwrite converts indexed images to RGB before writing data to JPEG files, because the JPEG format does not support indexed images.
Use the code below
[img, ~] = imread('yourImage.jpg');
[ind1, map1] = rgb2ind(img, 32);
imwrite(ind1, map1, 'yourImageNew.png'); % Don't change the extension to .jpg or .jpeg
[img2, map2] = imread('yourImageNew.png');
  1 件のコメント
ANITA JASMINE
ANITA JASMINE 2020 年 3 月 2 日
Thanks a lot. This code is working. Now I could store the image with map and take it for further processing..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by