Let us define a circle and assign different color to each one of the four quadrants.
MATLAB CODE:
%Radius
rad=400;
[X,Y]=meshgrid(-rad:rad);
nh = X.^2+Y.^2 <= rad.^2;
color_cir= uint8([size(nh,1) size(nh,2) 3]);
nh =uint8(nh);
%Color Blue
color_cir(1:rad,1:rad,1) = nh(1:rad,1:rad)*10;
color_cir(1:rad,1:rad,2) = nh(1:rad,1:rad)*100;
color_cir(1:rad,1:rad,3) = nh(1:rad,1:rad)*180;
%color pink
color_cir(rad:rad*2,1:rad,1) = nh(rad:rad*2,1:rad)*180;
color_cir(rad:rad*2,1:rad,2) = nh(rad:rad*2,1:rad)*10;
color_cir(rad:rad*2,1:rad,3) = nh(rad:rad*2,1:rad)*100;
%color Green
color_cir(rad:rad*2,rad:rad*2,1) = nh(rad:rad*2,rad:rad*2)*100;
color_cir(rad:rad*2,rad:rad*2,2) = nh(rad:rad*2,rad:rad*2)*180;
color_cir(rad:rad*2,rad:rad*2,3) = nh(rad:rad*2,rad:rad*2)*10;
%Color Red
color_cir(1:rad,rad:rad*2,1) = nh(1:rad,rad:rad*2)*180;
color_cir(1:rad,rad:rad*2,2) = nh(1:rad,rad:rad*2)*10;
color_cir(1:rad,rad:rad*2,3) = nh(1:rad,rad:rad*2)*10;
imshow(color_cir);
Concentric Circles:
Colored:
MATLAB CODE:
clc
clear all
rad1 = 600;
[X,Y] = meshgrid(-rad1:rad1);
nh = X.^2+Y.^2 <= rad1.^2;
color_cir = uint8([size(nh,1) size(nh,2) 3]);
nh = uint8(nh);
color_cir(1:size(nh,1),1:size(nh,2),1) = nh*10;
color_cir(1:size(nh,1),1:size(nh,2),2) = nh*1;
color_cir(1:size(nh,1),1:size(nh,2),3) = nh*2;
forrad = 550:-50:50
[X,Y] = meshgrid(-rad:rad);
diff = rad1-rad;
nh = X.^2+Y.^2 <= rad.^2;
nh = uint8(nh);
Pos1 = diff:(rad+diff-1);
Pos2 = diff+rad:(rad*2)+diff-1;
%Color Red
color_cir(Pos1,Pos1,1) = nh(1:rad,1:rad)*100 + color_cir(Pos1,Pos1,1);
color_cir(Pos1,Pos1,2) = nh(1:rad,1:rad)*10 + color_cir(Pos1,Pos1,2);
color_cir(Pos1,Pos1,3) = nh(1:rad,1:rad)*10 + color_cir(Pos1,Pos1,3);
%Color Green
color_cir(Pos1,Pos2,1) = nh(1:rad,rad:rad*2-1)*10 + color_cir(Pos1,Pos2,1);
color_cir(Pos1,Pos2,2) = nh(1:rad,rad:rad*2-1)*100 + color_cir(Pos1,Pos2,2);
color_cir(Pos1,Pos2,3) = nh(1:rad,rad:rad*2-1)*10 + color_cir(Pos1,Pos2,3);
%Color Blue
color_cir(Pos2,Pos1,1) = nh(rad:rad*2-1,1:rad)*10 + color_cir(Pos2,Pos1,1);
color_cir(Pos2,Pos1,2) = nh(rad:rad*2-1,1:rad)*10 + color_cir(Pos2,Pos1,2);
color_cir(Pos2,Pos1,3) = nh(rad:rad*2-1,1:rad)*100 + color_cir(Pos2,Pos1,3);
%Color yellow
color_cir(Pos2,Pos2,1) = nh(rad:rad*2-1,rad:rad*2-1)*150 + color_cir(Pos2,Pos2,1);
color_cir(Pos2,Pos2,2) = nh(rad:rad*2-1,rad:rad*2-1)*100 + color_cir(Pos2,Pos2,2);
color_cir(Pos2,Pos2,3) = nh(rad:rad*2-1,rad:rad*2-1)*10 + color_cir(Pos2,Pos2,3);
end
figure,imshow(color_cir);
EXPLANATION:
1. Draw a circle of radius 600.
2. Fill the circle with black color.
3. Draw another circle of radius 550 and fill the first quadrant will green, second quadrant with red, third quadrant with blue and the fourth quadrant with yellow color.
4. Place the smaller circle (radius 550) on the bigger circle (radius 600).
5. Draw another circle of radius 500 and repeat the same process till the radius of the smaller circle is 50.
Black and White:
MATLAB CODE:
clc
clear all
rad1 = 1250;
[X,Y] = meshgrid(-rad1:rad1);
nh = X.^2+Y.^2 <= rad1.^2;
color_cir = double([size(nh,1) size(nh,2) 3]);
nh = double(nh);
color_cir(1:size(nh,1),1:size(nh,2),1) = nh*1;
color_cir(1:size(nh,1),1:size(nh,2),2) = nh*1;
color_cir(1:size(nh,1),1:size(nh,2),3) = nh*1;
c1 = 0;
c2 = 255;
forrad = 1200:-50:50
[X,Y] = meshgrid(-rad:rad);
diff = rad1-rad;
nh = X.^2+Y.^2 <= rad.^2;
nh = double(nh);
Pos1 = diff:(rad+diff-1);
Pos2 = diff+rad:(rad*2)+diff-1;
%Second Quadrant
color_cir(Pos1,Pos1,1) = nh(1:rad,1:rad)*c1 + color_cir(Pos1,Pos1,1);
color_cir(Pos1,Pos1,2) = nh(1:rad,1:rad)*c1 + color_cir(Pos1,Pos1,2);
color_cir(Pos1,Pos1,3) = nh(1:rad,1:rad)*c1 + color_cir(Pos1,Pos1,3);
%First Quadrant
color_cir(Pos1,Pos2,1) = nh(1:rad,rad:rad*2-1)*c2 + color_cir(Pos1,Pos2,1);
color_cir(Pos1,Pos2,2) = nh(1:rad,rad:rad*2-1)*c2 + color_cir(Pos1,Pos2,2);
color_cir(Pos1,Pos2,3) = nh(1:rad,rad:rad*2-1)*c2 + color_cir(Pos1,Pos2,3);
%Third Quadrant
color_cir(Pos2,Pos1,1) = nh(rad:rad*2-1,1:rad)*c2 + color_cir(Pos2,Pos1,1);
color_cir(Pos2,Pos1,2) = nh(rad:rad*2-1,1:rad)*c2 + color_cir(Pos2,Pos1,2);
color_cir(Pos2,Pos1,3) = nh(rad:rad*2-1,1:rad)*c2 + color_cir(Pos2,Pos1,3);
%Fourth Quadrant
color_cir(Pos2,Pos2,1) = nh(rad:rad*2-1,rad:rad*2-1)*c1 + color_cir(Pos2,Pos2,1);
color_cir(Pos2,Pos2,2) = nh(rad:rad*2-1,rad:rad*2-1)*c1 + color_cir(Pos2,Pos2,2);
color_cir(Pos2,Pos2,3) = nh(rad:rad*2-1,rad:rad*2-1)*c1 + color_cir(Pos2,Pos2,3);
if(c2 > 1)
c1 = 255;
c2 = -255;
else
c1 = -255;
c2 = 255;
end
end
color_cir = uint8(color_cir);
figure,imshow(color_cir);
EXPLANATION:
1. Draw a circle of radius 1250.
2. Fill it with black color.
3. Draw another circle with radius 1200.
4. Fill second and fourth quadrant of the smaller circle with white color.
5. Fill First and Third quadrant of the smaller circle with black color.
6. Place the smaller circle on the bigger circle.
7. Define another circle of radius 1150.
8. Fill second and fourth quadrant of the smaller circle with black color.
9. Fill First and Third quadrant of the smaller circle with white color.
10. Now place this circle on the bigger one. Repeat this process with smaller circles and by interchanging black and white color on the quadrants for each circle.
Concentric circle - 2:
MATLAB CODE:
%Define the matrix
[x,y] = meshgrid(-600:600);
%Preallocate
ccircle = zeros(size(x));
for i = 500:-10:1
Tmp = x.^2 + y.^2 <= i*i;
%Find the gradient of the image
[Gmag,Gdir] = imgradient(Tmp);
ccircle = ccircle + Gmag;
end
figure,imshow(ccircle);
Keine Kommentare:
Kommentar veröffentlichen