Alpha channel in image
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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
2017 年 12 月 4 日
編集済み: Margareta Drozdikova
2017 年 12 月 26 日
Thanks for answer. I have created the newfilter.png but I have still problem lay this newfilter on color picture. The picture on the bottom is uint8 513X513. I have attached the result. Thanks for help
Walter Roberson
2017 年 12 月 5 日
image(newfilter(:,:,[1 1 1]), 'AlphaData', filter_alpha);
the newfilter(:,:,[1 1 1]) effectively converts the greyscale array newfilter into an RGB array for drawing purposes.
Margareta Drozdikova
2017 年 12 月 5 日
編集済み: Margareta Drozdikova
2017 年 12 月 26 日
Thanks. I did it, but the result is weird. The left part is rgb picture and on this picture I need to lay transparent circle. I did it, how you said. (Thanks :) ) but It doesnt look goog. In the circle I have to have color map
Walter Roberson
2017 年 12 月 5 日
What the above suggests to me is that the picture to the left is either much smaller than the filter image, or else that the picture on the left has been created with a different coordinate system.
If the problem is one of coordinate systems, then you can get this almost right by putting up the color graph first and then using
ax = gca;
XL = get(ax, 'XLim');
YL = get(ax, 'YLim');
image(newfilter(:,:,[1 1 1]), 'AlphaData', filter_alpha, 'XData', XL, 'YData', YL );
This is not exactly right because a half-pixel border around the image will be outside of the existing boundaries -- but try it and see if it is close enough before I worry about calculating the formula for the correction to put the pixel centers in the right locations.
Margareta Drozdikova
2017 年 12 月 5 日
Thanks. It doesnt work correct. The size of color picture is 513x513 uint8 the same it is at newfilter. I dont know. I will think more about it
Walter Roberson
2017 年 12 月 5 日
After you image() the bottom image, you need to colormap() the appropriate colormap for it, unless it is an RGB image.
Margareta Drozdikova
2017 年 12 月 7 日
and one more question. What does it mean A = double(x==0); ?
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 件)
カテゴリ
ヘルプ センター および File Exchange で Modify Image Colors についてさらに検索
タグ
参考
2017 年 12 月 4 日
2017 年 12 月 26 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
