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

How to create Video from still image


                  Using a single JPEG image, we can create image sequences.  To create image sequences, we need to convert the image into frame. The matlab function   ‘im2frame’ is used to create frame from an image. In this example, I took an image and created some frames by performing rotation operation on that image.
                             Initially, I pre allocated a structure array.  When the function ‘im2frame’ is used on an image, a frame is created.  The frame is a structure that contains the cdata and the colormap.


Example:
I=imread(‘ball.jpg’);
frame(1)=im2frame(I);
frame(1)
ans =
       cdata: [323x400x3 uint8]
      colormap: []
After allocating the space for the frames, I rotated the image from 1 to 360 degrees with the interval of 10 degrees.  36 frames will be obtained.
During each rotation operation, the size of the image will be modified. So, I resized the image to the original size after every rotation.
MATLAB CODE:
%Create a video from still image
I=imread('ball.jpg');
m=size(I,1);
n=size(I,2);
j=1;
%Preallocate the structure array
%The fields are 'cdata' and 'colormap'
%The size should be 1xm
frame=struct('cdata',1,'colormap',cell([1 36]));

for i=1:10:360
    %Rotate the image
    Im=imrotate(I,i);
    %To convert an image to frame use the function 'im2frame'.
    frame(j)=im2frame(imresize(Im,[m n]));
j=j+1;
end

%scz=figure;
%set(scz, 'position', [300 100  size(I,1)+200 size(I,2)]);
%movie(scz ,frame,1,30);

%Play the image sequence with fps=10.
implay(frame,10);






We can either use ‘movie’ function or ‘implay’ function to play the video.
Function: movie
If the ‘movie’ function is used. Then we can specify the window size and the position.
%movie(scz ,frame,N,FPS);

N-number of times
FPS-Frames per second
Function :  implay
It can take two parameters, frames and the FPS.
like button Like "IMAGE PROCESSING" page

Boundary Extraction in MATLAB


Boundary Extraction in MATLAB
Let A be an Image matrix and B be a structuring element.


Formula for Boundary Extraction:



Steps to be followed:
·         Convert the image into binary image.
·         Perform Erosion:
                Erode binary image A by structuring element B. (i.e)
                     
               
·         Subtraction:
              Subtract the binary image A from the Eroded image.(i.e)

             



A=imread('banana.jpg'); 


C=rgb2gray(A);
C(C<225)=0;
s=strel('disk',4,0);%Structuring element
D=~im2bw(C);%binary Image
F=imerode(D,s);%Erode the image by structuring element
figure,imshow(A);title('Original Image');
figure,imshow(D);title('Binary Image');


%Difference between binary image and Eroded image
figure,imshow(D-F);title('Boundary extracted Image');



Example 2:









A=imread('nutsbolts.tif');
s=strel('disk',2,0);
F=imerode(A,s);
figure,
subplot(2,1,1);
imshow(A);title('Binary Image');
subplot(2,1,2);
imshow(A-F);title('Boundary extracted Image');







like button Like "IMAGE PROCESSING" page

Sobel edge detection

         The gradient of the image is calculated for each pixel position in the image.






























The procedure and the MATLAB  code for sobel edge detection without using MATLAB built-in function:






































MATLAB CODE:


A=imread('peppers.png');
B=rgb2gray(A);

C=double(B);


for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Sobel mask for x-direction:
        Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
        %Sobel mask for y-direction:
        Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
     
        %The gradient of the image
        %B(i,j)=abs(Gx)+abs(Gy);
        B(i,j)=sqrt(Gx.^2+Gy.^2);
     
    end
end
figure,imshow(B); title('Sobel gradient');
Sobel Gradient

%Define a threshold value
Thresh=100;
B=max(B,Thresh);
B(B==round(Thresh))=0;

B=uint8(B);
figure,imshow(~B);title('Edge detected Image');












Edge detected Image



Edge detected Image(Threshold value:35)
The edge detected image can be obtained from the sobel gradient by
using a threshold value.



  • If the sobel gradient values are lesser than the threshold value then replace it with the threshold value.
    if f < threshold value then
    f = threshold value.

























To avoid complex computation, the gradient can also be computed using the formula:




The Image obtained from computing X-direction derivative:













The Image obtained from computing Y-direction derivative:

Also Check  Sobel Edge Detection - Part 2







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