Differences in image output between transparent pngs using imread
4 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!