When reading an image, why is the map value blank?

Hi,
I am currently doing a project relating to image compression. And I'm trying to figure out a slight error, my code reads like this to read the image
[uploadedImage, map] = imread('Test.png');
But when i look at the variable uploadedImage it shows a 3-dimensional array. Which is fine, however the map variable has a value of [ ]. Can anyone tell me why this is happening?

 採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 16 日

1 投票

This is common.
RGB images are r x c x 3 with an empty map
CMYK images (tiff only) are r x c x 4 with an empty map
RGBA images are sometimes r x c x 4 with an empty map, but are sometimes r x c x 3 with a third output that can indicate alpha
Grayscale images are r x c with an empty map. These have an implicit grayscale map.
Gray+alpha images are uncommon but are r x c x 2 with an empty map
Pseudocolor images are r x c with a nonempty map and can be converted to rgb with ind2rgb()

3 件のコメント

Kishan Narotam
Kishan Narotam 2019 年 7 月 16 日
Ah, that makes sense. Thank you so much.
Carla Mirabella
Carla Mirabella 2019 年 10 月 5 日
編集済み: Carla Mirabella 2019 年 10 月 5 日
Could you explain how you can concatenate the two arrays image and map if they have different dimensions?
Walter Roberson
Walter Roberson 2019 年 10 月 5 日
combined = ind2rgb(FirstImage, FirstMap);
combined_vertical(end+1:end+size(SecondImage,1), 1:size(SecondImage,2), :) = ind2rgb(SecondImage, SecondMap);
combined_horizontal(1:size(SecondImage,1), end+1:end+size(SecondImage,2), :) = ind2rgb(SecondImage, SecondMap);
If you want to get out a pseudocolor image then
combined_map = unique( [FirstMap; SecondMap; 0 0 0], 'rows');
pseudo_vertical = rgb2ind(combined_vertical, combined_map);
pseud_horizontal = rgb2ind(combined_horizontal, combined_map);
The 0 0 0 added before the unique is in case the original color maps did not have a pure black: when the images do not have the dimensions then padding was automatically added that is all 0 0 0 so we have to accomodate that in the color map.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

製品

リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by