フィルターのクリア

How do I fade colors into each other?

1 回表示 (過去 30 日間)
Krish Desai
Krish Desai 2015 年 10 月 3 日
コメント済み: Image Analyst 2015 年 10 月 4 日
I'm trying to get red in the top right, purple in the top left, blue in the bottom right, and green in the bottom left. However, instead of fading together the colors are staying separate of each other. What am I doing wrong?
r=256;
c=256;
d=3;
A=zeros(r,c,d);
increase=linspace (0,1,256);
decrease= linspace (1,0,256);
%Top
for i=1:256
%Top
A(1:128,i,1)=1;
A(1:128,i,3)=increase(i);
%Bottom
A(128:256,i,3)=increase(i);
A(128:256,i,2)=decrease(i);
end
imagesc(A)
I add the following into my for loop: %left
A(i,1:128,1)=decrease(i);
A(i,1:128,2)=increase(i);
%right
A(i,128:256,1)=decrease(i);
A(i,128:256,3)=increase(i);
Now I get a weird triangle thing, what am I doing wrong? I want all of them to fade into each other.

採用された回答

Image Analyst
Image Analyst 2015 年 10 月 4 日
Try this:
rows = 256;
oneColumn = ((rows-1) : -1 : 0)';
redChannel = uint8(repmat(oneColumn, [1, rows]));
blueChannel = uint8(toeplitz((rows-1):-1:0));
greenChannel = uint8(toeplitz(0:(rows-1)));
triangleMask = logical(triu(ones(rows, rows)));
greenChannel(triangleMask) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
  2 件のコメント
Krish Desai
Krish Desai 2015 年 10 月 4 日
just trying to understand how this works...how would I move the colors around, for instance how could I switch the red and purple?
Image Analyst
Image Analyst 2015 年 10 月 4 日
Just consider watch color plane one at a time. Then figure out where the 0's need to be and where the 255's need to be and use repmat(), toeplitz(), or the colon operator to replicate a single vector over the whole array.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by