Fourth Year – Software Engineering Image Processing Fourth Year – Software Engineering Introduction
Reading, writing and displaying images myImg = imread(’foo.ext’) reads file foo.ext into array myImg, image format is determined by the file extension (jpg, tiff, tif, gif, bmp, png, ...) imwrite(anImg, ’foo.ext’) writes the image anImg to the file foo.ext, where the image format is chosen according to the extension ext. Valid extensions are: tif, tiff, jpg, `` jpeg, gif, png imshow(myImg) displays the image myImg as gray- scale, binary or color image depending on the data type of myImg figure(n) opens a new window with number n, the next
Color planes The green and red color plane of image rgbimage.jpg are swapped: f = imread(’rgbimage.jpg’); red = f(:,:,1); g(:,:,1) = f(:,:,2); g(:,:,2) = red; g(:,:,3) = f(:,:,3); imshow(g);
Image Processing Read Image Display image Convert RGB to grayscale imread(‘path’) ex: img=imread('D:\images\sherko.jpg'); Display image imshow(img); Convert RGB to grayscale rgb2gray(img); figure; grayscaleimage=rgb2gray(img); Divide figure into grid subplot(row,column,location);
Image Processing ex: subplot(2,2,1);imshow(img);title('OrignalImage'); subplot(1,2,2);imshow(grayscaleimage);title('GrayScaleImage'); color spaces RGB subplot(2,2,1);imshow(img);title('OrignalImage'); subplot(2,2,2);imshow(img(:,:,1));title('RChannelValues'); subplot(2,2,3);imshow(img(:,:,2));title('GChannelValues'); subplot(2,2,4);imshow(img(:,:,3));title('BChannelValues');
Image Processing Resize Image imresize(img, scale) ex: resizeimage=imresize(img,0.5); imshow(img); figure; imshow(resizeimage); Imresize(img,[numrow numcolumn]); [m n ~]=size(img); %color image resizeimage=imresize(img,[m/2 n/2]);
Image Processing Crop Image Write Image imcrop(img,[xmin ymin width height]); ex: croppedimage=imcrop(img,[50 70 100 150]); Write Image imwrite(image,filename,fmt) imwrite(croppedimage,strcat('D:\images\Mypicture','.bmp'));