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

Array Search

Let's search the cell array and find the index. This simple example will help to find the index in cell array of large size.

names={'Hilda' 'Helen' 'Ada'; 'Matthew' 'Jenny' 'Justin'; 'Agnes' 'Merlin' 'Mark';}

names = 

    'Hilda'      'Helen'     'Ada'   
    'Matthew'    'Jenny'     'Justin'
    'Agnes'      'Merlin'    'Mark'  

I need to know whether the name 'Justin' exists in this cell array

find(strcmp(names,'Justin')==1)

ans =

     8

Let me retrieve the name 'Justin'  , using the index

names{8}

ans =

Justin


like button Like "IMAGE PROCESSING" page

Adding elements to a 2d array

A=[100 230 11; 22 10 15; 2 3 90;]

A =

   100   230    11
    22    10    15
     2     3    90

To add a row at the beginning:

A=[[10 20 30]; A]

A =

    10    20    30
   100   230    11
    22    10    15
     2     3    90

To add a row at the end:

A=[A; [10 20 30];]

A =

   100   230    11
    22    10    15
     2     3    90
    10    20    30


To add a column at the beginning:

A=[[10; 20 ;30] A]

A =

    10   100   230    11
    20    22    10    15
    30     2     3    90


To add a column at the end:

A=[A [10; 20 ;30]]

A =

   100   230    11    10
    22    10      15    20
     2     3        90    30


To add a row in the middle:


A=[10 12 14 16; 3 6 9 12; 4 8 12 16; 5 10 15 20;]

A =

    10    12    14    16
     3     6     9    12
     4     8    12    16
     5    10    15    20


A=[A(1:2,:); [8 16 24 32]; A(3:4,:);]

A =

    10    12    14    16
     3     6     9    12
     8    16    24    32
     4     8    12    16
     5    10    15    20

To add a column in the middle:


A=[A(:,1:2) [100; 200; 300; 400;] A(:,3:4)]

A =

    10    12   100    14    16
     3     6     200     9    12
     4     8     300    12    16
     5    10    400    15    20



like button Like "IMAGE PROCESSING" page

Tiling effect in MATLAB


Tiling effect

original Image
          Let’s make some random rectangles from the image. 

MATLAB CODE:

A=imread('tulip2.jpg');
C=uint8(zeros(size(A)));
i=1; j=1;
col=0;
row=0;
m=1;n=1;
%change the rsz and csz value to obtain pieces in different sizes
rsz=15;
csz=36;

%change the tsz_row and tsz_col values to make some gaps between the pieces.

tsz_row=3;
tsz_col=5;


while ( i < size(A,1))
%check whether i is less than size of (A,1)

while(m+i+row < size(A,1)&& n+j+col < size(A,2))

    
        %size of the tiles varies depending upon the random number
        C(m+i:m+i+row,n+j:n+j+col,:)=A(i:i+row,j:j+col,:);
      
        m=ceil(rand(1)*tsz_row);
        n=ceil(rand(1)*tsz_col);
        col=ceil(rand(1)*csz);
        row=ceil(rand(1)*rsz);
        j=j+col;
       
   
    end
     i=i+row;
     j=1;
end
figure,imshow(C);
With small gaps


With Large gaps
Subscribe to 'Image processing' to get the complete code.


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