필터 지우기
필터 지우기

Differences in image output between transparent pngs using imread

조회 수: 2 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by