Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Rainbow

Last night I was watching dragon tales, a cartoon series. I saw a scene with rainbow and my mind started to think to implement that rainbow in MATLAB. To my surprise, what I learned in the tenth grade mathematics came in handy, the equation of a circle.  Many times our lower class basic mathematics will come throughout our life. As a result I have started to read tenth grade mathematics once again ;-)
I followed the same procedure, 'How to draw a circle'. Instead of finding the midpoint for x co-ordinate I took the image size, so that I may get a half a circle.
sz=400;
rad=200;
clear RGB
RGB(1:sz,1:sz,1:3)=255;
RGB=uint8(RGB);
[x y z]= find(RGB==255);

xc=sz;
yc=ceil((sz+1)/2);




for i=1:12
    radius=(rad-10*i).^2;
    r=find(((x-xc).^2+(y-yc).^2)<=radius);
   
for j=1:size(r,1)

    if(mod(i,2)==0)
                RGB(x(r(j)),y(r(j)),:)=255;
    end
            if(mod(i,3)==1)
               RGB(x(r(j)),y(r(j)),:)=0;
            end
        
end



end



B=rgb2gray(RGB);


D=edge(B);
SE=strel('disk',2);
D1=~imdilate(D,SE);

I colored the image based on label

[BW ,L]=bwlabel(D1,8);

    mycolor(:,1)=[128;128;255];
    mycolor(:,2)=[215;0;0];
    mycolor(:,3)=[255;128;0];
    mycolor(:,4)=[255;255;0];
    mycolor(:,5)=[0;128;64];
    mycolor(:,6)=[10;160;220];
    mycolor(:,7)=[0;0;70];
    mycolor(:,8)=[65;0;128];
    mycolor(:,9)=[128;128;255];
for n=1:9
[r c]=find(BW==n);

for i=1:size(r,1)
            RGB(r(i,1),c(i,1),:)=mycolor(:,n);
end
end
imshow(RGB);


like button Like "IMAGE PROCESSING" page

Checkerboard

                 I came across the matlab built in function checkerboard. And I tried to implement my own code.
First I declared the size of each square and then the number of rows and columns. Then I declared two matrixes initialized with zeros and ones. Using mod 2 I changed the colors or ones and zeros alternatively.
MATLAB CODE:
%Size of the square
sz=45;
%Number of rows
xvalue=8;
%Number of columns
yvalue=8;
%Intialize matrix A with zeros and matrix B with ones
A=zeros([sz sz]);
B=ones([sz sz]);
clear C
 m=sz;
 n=1;
 num=2;
for i=1:xvalue
    n1=1;
    m1=sz;
   
    for j=1:yvalue
        if(mod(num,2)==0)
        C(n:m,n1:m1)=A;
        num=num+1;
        else
        C(n:m,n1:m1)=B;
        num=num+1;
        end
       
        m1=m1+sz;
        n1=n1+sz;
    end
    if(mod(yvalue,2)==0)
    num=num+1;
    end
    n=n+sz;
    m=m+sz;
end
imshow(C)

8X8 size:45

8X20 size:15
              
like button Like "IMAGE PROCESSING" page

Color Palette

This is my first attempt on designing a color palette. Of course, this looks quite simple.
The palette contains primary colors R,G and B.
%size of the square
sz=50;
%Number of rows
xvalue=10;
%Number of Columns
yvalue=10;
%Initialize the matrix with zeros
RGB=zeros([sz+2 sz+2 3]);
%The image shade from darker to lighter.Instead of 255 give values lesser than 255 and see the different shades
v=round(255/yvalue);

clear C
 m=sz+2;
 n=1;
    %The same color repetition. If you specify val=1 then the colors  R,G,B
    %will occur repeatedly
    val=floor(xvalue/3);
   
    inc=1;
for i=1:xvalue
    n1=1;
    m1=sz+2;
    if(inc==1)
        %Red color will be displayed
    num1=20;
    num2=1;
    num3=1;
    elseif(inc==2)
        %Green color will be displayed
    num1=1;
    num2=20;
    num3=1;
    elseif(inc==3)
        %Blue color will be displayed
    num1=1;
    num2=1;
    num3=25;
   
    end
    for j=1:yvalue
        RGB(2:sz+1,2:sz+1,1)=num1*v*j;
        RGB(2:sz+1,2:sz+1,2)=num2*v*j;
        RGB(2:sz+1,2:sz+1,3)=num3*v*j;
       
              
        C(n:m,n1:m1,:)=RGB;
             
        m1=m1+sz;
        n1=n1+sz;
            
      
    end
    n=n+sz;
    m=m+sz;
    if(mod(i,val)==0)
       
        inc=inc+1;
    
        if(inc>3)
            inc=1;
        end
    end
   
   
end

C=uint8(C);
imshow(C);

10X10

5X10
             



like button Like "IMAGE PROCESSING" page
Next Post Home
Google ping Hypersmash.com