Image processing in octave

For performing image processing functions on image, Firstly you have to load an image.

//Loading of image

octave:1> n1=imread(“/home/manpreet/Desktop/nature1.jpg”);

// Displaying of image

octave:2> imshow(n1);

// Check size of image

octave:3>size(n1)

//Image processing functions which can be possible with Octave-Forge package .

  • size(n1)         // show size of RGB image with dimensions and 3 for color matrics.
  • image(n1);     //show matrix of image.
  • rgb2gray(n1)   // convert image into gray.
  • r=imrotate(n1, -180);  //here n1 is image and -180 is a THETA angle.
  • c=imcomlement(n1);   // show negative of image.
  • contrast=imadjust(img); // contrast the image.
  • contrast= imadjust(img, [0.3  0.7,], [] );
  • r=imresize(n1, 0.2);   //it will  remove pixel from image.
  • no=imnoise(n1,”salt and pepper”);   //  add noise into image.
  • imadd(n1,n2)   // add 2 images in one single image.
  • imabsdiff(n1,n2) OR subtract=n1-n2   // find difference of 2 images.
  • immultiply(n1,n2)   // multiply 2 images in one.
  • type=im2double(img)   // change datatype of image. type whos type for display of datatype of image.
  • imwrite(img)     //save image for future use.

// Separate each matrix in RGB image. Below code show image only in Red color with Red matrix. Similarly you can do this for Green and Blue (without Octave-Forge package).

octave:1> n1=imread(“/home/manpreet/Desktop/nature1.jpg”);

octave:2> imshow(n1);

octave:3>size(n1); //show size and 3. 3  stands for 3 matrix of RGB. One matrix for red, one for green ,one for blue.

octave:4>red_n1=n1;

octave:5>red_n1(: , : , 2)=0; // assign 0 to Green matrix. clear it

octave:5>red_n1(: , : , 3)=0;

octave:5>figure(2); //open new window.

octave:5>imshow(red_n1);

// Another functions of image processing in octave (with octave-forge package).

1) imerode(): erode image with rolling balls. Erosion is performed with structureing element return by strel function.

   SE=strel(‘ disk ‘, 10);

   erode_img=imerode(img, SE);

   imshow(erode_img);

2) imdilate: Dispaly binary image with rolling ball structureing elements.The argument SE is a structuring element object, or  array of structuring element objects, returned by the strel function.

   SE=strel(‘ disk ‘, 5);

   erode_img=imdilate(img, SE);

   imshow(erode_img);

3) Morphological operation

 (i) imopen(): Morphologically open image with disk structureing element.

SE=strel(‘ disk ‘, 5);

morph_img=imopen(img, SE);

imshow(morph_img);

(ii) imclose: Use Morphological Closing to Fill Gaps in an Image. Use morphological closing to join the circles in an image together by filling in the gaps between them and by smoothing their outer edges.

  morph_close=imclose(img, SE);

  imshow(morph_close);

3) blurring: it blur the image using fspecial() and imfilter().

   f=fspecial(‘disk’, 10);

   blur=imfilter(img,f);

4) imfilter(): it filter the image according to value passed to fspecial().

   f=special(‘motion’ 0.5),

   filter_img=imfilter(img, f);

   imshow(filter_img);

****************kernel functions********************

  •  gaussian kernel:

        f=special(‘gaussian’ , 0.5);

       gausi_ker=imfilter(img, f);

  • Lapacian kernel:

       f=special(‘lapacian’ , 10);

       lap_kernel=imfilter(img, f);

 

  • sobel  kernel:

         f=special(‘sobel’ , 0.5);

         sobel_ker= imfilter(img, f)

Follow this link for and help for more datail of functions: http://in.mathworks.com/help/images/functionlist.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s