Azzera filtri
Azzera filtri

How do I fade colors into each other?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Image Analyst
Image Analyst il 4 Ott 2015
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 Commenti
Krish Desai
Krish Desai il 4 Ott 2015
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 il 4 Ott 2015
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by