Transparent background+setting alpha data

2 ビュー (過去 30 日間)
Mohamed
Mohamed 2012 年 9 月 30 日
Hi: I have matrix
x=[1 2 3; 0 2 3;0 0 3];
I want to create a png file where the 0s are transparent and the rest of values are half transparent...I tried the following:
x(x<=0)=NaN;
h=imagesc(x);
axis image
set(h,'alphadata',~isnan(x))
set(gca,'color','none');
set(gca, 'visible', 'off') ;
export_fig asda.png -transparent
(search expor_fig on this site you will find it,saveas acts weird sometimes so I prefer this one).
Problem is how do I make the rest of the ~isnan values half transparent?
if I use alpha(.5) the NaN will get back their colors (cancels the 'alphadata' command)
Thanks,

採用された回答

Jan
Jan 2012 年 9 月 30 日
編集済み: Jan 2012 年 9 月 30 日
x = [1 2 3; 0 2 3;0 0 3];
x = x / max(x(:)); % Scale to [0,1]
A = repmat(0.5, size(x));
A(x == 0) = 1; % 100% transparent
imwrite(x, 'asda.png', 'Alpha', A);
I do not find in the documentation, if 100% transparency is 1 or 0. So please test thiy.
  2 件のコメント
Mohamed
Mohamed 2012 年 9 月 30 日
Thanks Jan. However, that reminded me of another issue I was trying to prevent. I am producing hundreds of this kind of matrices. And I want them all to have the same caxis([cmax cmin]). I don't know how to do so with imwrite. That's why I am creating my images from existing figures. I assume the 'alpha' property doesn't work here (what I am doing)? please correct me if I am wrong. Thanks again
Mohamed
Mohamed 2012 年 9 月 30 日
Actually it does work. so my solution would be similar to yours but. A(x == 0) = 0; and add line alpha(A);
Appreciate it!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 9 月 30 日
Have you seen the official Mathworks documentation: http://www.mathworks.com/help/matlab/ref/imwrite.html#f25-742371
  1 件のコメント
Mohamed
Mohamed 2012 年 9 月 30 日
Please read above ( first time to post here, don't know if you got notification or something) Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by