Pages

Monday, March 28, 2022

Image processing with Matlab : Popular Command & Instruction

 Basic image processing functions:  

  • Read an Image : imread() 
The 'imread()' command will read an image into a matrix:
example : img = imread(abc.jpg); 

  • Size of an Image :  size() 

example:    size(img) 
It's a 340x650 matrix with 3 RGB channels. 

  • Display an image: imshow()
To show our image, we will use imshow() command.
example : imshow(img) 
  • Export an Image : imwrite()
imwrite(img,'s.png','png'); 
  • Clear the 'command window' in MATLAB? : clc 
We can clear our MATLAB's 'command window' by using this command
  • imaqhwinfo()
This will return the information about all the adaptors available on the system.
 
  • vid = videoinput ('winvideo',1);
  • preview (vid)
Suppose you want to preview your webcam then type


  • vid=videoinput('winvideo',1);
  • I=getsnapshot(vid);
  • save data
Take photos from your webcam 
  • vid=videoinput('winvideo',1);
  • for i=1:10 
         I=getsnapshot(vid);
         Fname=['Image',num2str(i),'.jpg'];
         imwrite (I,Fname,'jpg');
         pause(1);
     end
Take 10 photos from the webcam and rename them in your formate
  • Create a function in Matlab 
function [ output_args ] = functionName( input_args )
imshow(input_args);

end

  • Automatic alignment of code lines in editor, do EDIT->Select ALL, then TEXT -> Smart INDENT
  • Create Own Photo (Binary)
col=256;
row=256;
img=zeros(row,col);
img(100:100,:)=1.5;
img(:,100:100)=1.5;
imshow(img);


  • Crop an Image 
a=imread('abc.jpg');
i=imcrop(a);
imshow(i)
  • rotate an image in Matlab and Subplot
a= imread ('abc.jpg');
i = imrotate(a,180,'bilinear');
i2 = imrotate(a,45,'nearest');
subplot(2,1,1)
imshow(i)
subplot(2,1,2)
imshow(i2)

No comments:

Post a Comment