필터 지우기
필터 지우기

Change white pixels to invisible

조회 수: 11 (최근 30일)
Jacob L
Jacob L 2020년 11월 26일
댓글: Matt J 2020년 11월 26일
Hi, I have a .png I'm trying to overlay on top of an existing figure in matlab. Most of the image is just a white background. Is it possible to overlay everything but the white background from the .png to the existing figure? In other words, can I make the white background transparent/invisible?
The image is RGB 'unit8'. When I do this:
alphachannel = all(image == 255, 3);
imwrite(image,'invisible.png','Alpha',alphachannel);
This error comes up:
Error using writepng>parseInputs (line 349)
The value of 'alpha' is invalid. Expected input to be one of these types:
double, uint8, uint16
Instead its type was logical.
When I do this:
alphachannel = double(all(image ~= 255, 3));
imwrite(image,'invisible.png','Alpha',alphachannel);
The .png file appears to have the invisible pixels instead of the white pixels, but ,when I try to overlay the new .png on top of the existing figure in matlab, the "invisible" background is black. Is there anything I can do? Any help is appreciated, thanks.

답변 (1개)

Matt J
Matt J 2020년 11월 26일
편집: Matt J 2020년 11월 26일
Shouldn't you have
alphachannel = 1-double(all(image == 255, 3));
  댓글 수: 3
Matt J
Matt J 2020년 11월 26일
I recommend you attach all images so we can play with them.
Jacob L
Jacob L 2020년 11월 26일
Okay - here is a summary of what's going on:
Starting with the Teddy_Bear.png
Then using
teddyBearProcessed = padarray(image,[1000,1000],255,'post');
to get Teddy_Bear_Padded.png
Then using
shiftedTeddy = imtranslate(image,[150, 150],'FillValues',255);
to get Teddy_Bear_Shifted.png
Then using
alphachannel = 1-double(all(image == 255, 3));
imwrite(image,'invisible.png','Alpha',alphachannel);
to get Teddy_Bear_Invisible.png
In the meantime I have another figure open in MATLAB. The output of the figure is saved in the attached as Stationary_Teddy_Centroid.png.
Then using
hold on
imshow('Teddy_Bear_Invisible.png');
to get problem.png.
What I'm trying to do is move the teddy bear on the screen so I can see the the path it takes. Kind of like how the path of the arm is seen in Stationary_Teddy_Centroid.png.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by