使白色背景透明png Matlab [英] Make white background transparent png matlab

查看:107
本文介绍了使白色背景透明png Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除我从创建的代码中获得的png图片上的白色背景.这是我得到的图片:

I am trying to remove the white background on my png picture I get from a code I created. This is the picture I get:

我想使白色背景透明,因为我有一些图像需要使用灌注技术进行组合.

I want to make the white background transparent, because I have several of those images that I want to combine using imfuse.

这是我的工作(我的照片称为"A1.png"):

What I do is this (my picture is called 'A1.png'):

A1=imread('A1.png');
D=zeros(size(A1));
D(A1==255) =1;
imwrite(A1,'A11.png','alpha',D);

但是我收到这样的错误 使用writepng> parseInputs时出错 (第349行) "alpha"的值无效. 预期的输入尺寸为829x600 实际尺寸为829x600x3.

However I get an error like this Error using writepng>parseInputs (line 349) The value of 'alpha' is invalid. Expected input to be of size 829x600 when it is actually size 829x600x3.

829x600x3 uint8是A1的大小.我知道我需要摆脱x3的问题.但是我不知道是否是在我的代码中保存图片或更早的时间.

829x600x3 uint8 is the size of A1. I understand I need to get rid of the x3 thing. But i don't know if it's when I save the pic or earlier in my code.

你们怎么看?

推荐答案

您只需创建一个尺寸较小的D.这是代码

You need simply create D with one less dimension. Here is the code

D = zeros( size(A(:,:,1)) );
D( all( A==255, 3 ) ) = 1; 
imwrite(A,'A11.png','alpha',D);

这篇关于使白色背景透明png Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆