Differences in image output between transparent pngs using imread

4 ビュー (過去 30 日間)
Rob Blackburn
Rob Blackburn 2024 年 5 月 2 日
コメント済み: Rob Blackburn 2024 年 5 月 3 日
Hi, I've been doing some work with image processing, and reading two difference transparent pngs seem to give two different output.
[A, map, transparency] = imread('https://images.fotmob.com/image_resources/logo/leaguelogo/109.png');
gives a 192x192 uint8 for 'A', a 256x3 double for 'map', and a 192x192 double for 'transparency'
However, running the same code on a different transparent png gives a different output structure
[A, map, transparency] = imread('https://images.fotmob.com/image_resources/logo/teamlogo/9818.png');
gives a 128x128x3 uint8 fo 'A', nothing for 'map', and 128x128 uint8 for 'transparency'.
I would like to understand why these outputs are different for the same file type, and also if there is a way to convert the first case into the second case, as the second case is the most important for me

採用された回答

DGM
DGM 2024 年 5 月 2 日
A PNG can be an indexed image with or without associated transparency data.
A PNG can also be a plain grayscale (I) or truecolor (RGB) image, either of which may also have associated alpha (IA or RGBA).
It's not uncommon for image file formats to support multiple different ways of representing data. Some like GIF only support indexed images. Some like JPEG don't support indexed images at all. PNG is flexible.
You can convert indexed color images to RGB. The following code presumes that the input is an indexed-color image.
inname = '109.png';
outname = 'test.png';
[inpict,map,alpha] = imread(inname); % read indexed image with alpha
outpict = ind2rgb(inpict,map); % convert indexed to RGB
imwrite(outpict,outname,'alpha',alpha) % write with alpha
  1 件のコメント
Rob Blackburn
Rob Blackburn 2024 年 5 月 3 日
Thanks very much! This has fixed my issue

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by