필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by