필터 지우기
필터 지우기

Alpha channel in image

조회 수: 28 (최근 30일)
Margareta Drozdikova
Margareta Drozdikova 2017년 12월 4일
편집: Margareta Drozdikova 2017년 12월 26일
Hi, I have a white circle (255) and background is black (0), Picture is saved as png and is in grayscale, size 513x513. I need one thing. The white circle has to be transparent and black part no. How can I do this?
x=imread('filter.png');
[M,N]=size(x);
A=zeros(M,N);
for i=1:M
for j=1:N
if (x(i,j)==255)
A(i,j)=1;
end
end
end
imwrite(x,'filter.png','Alpha',A)
but i dont know if it is OK. I have this picture lay on another picture, so in white circle I will see second picture and in black part I will see black. Thanks for any help

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 4일
Your basic technique was correct, but your code can be written much more efficiently.
x = imread('filter.png');
A = double(x==0);
imwrite(x, 'newfilter.png', 'Alpha', A);
"I have this picture lay on another picture,"
If you are reading the new image in using imread() then you are probably not handling the alpha correctly at that time:
image(ArrayForImageToGoOnTheBottom);
[newfilter, map, filter_alpha] = imread('newfilter.png');
image(newfilter, 'AlphaData', filter_alpha);
  댓글 수: 8
Margareta Drozdikova
Margareta Drozdikova 2017년 12월 7일
and one more question. What does it mean A = double(x==0); ?
Image Analyst
Image Analyst 2017년 12월 7일
You are checking if x is zero. The result of x==0 will be a logical variable with values of true or false.
Using double() casts the data type from logical to double, so that now A will be a double with a value of 0 or 1, NOT a logical with a value of true or false.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by