EXPERIMENT 1: IMAGE AND OPERATIONS ( a) Example: WAP to create a Checkerboard image. I = checkerboard(20,5,7); figure, imshow(I) Task: Write a user defined function() i.e. my_checkerboard ' instead of using the inbuilt ‘checkerboard()' function. Hint: ones(20), Zeros(20) MATLAB CODE: function jrb = my_checkerboard(j, r, b) img=[zeros(j),ones(j);ones(j),zeros(j)]; pic=repmat(img, r, b); imshow(pic); end OUTPUT: On the editor option from the menu bar , select “ Run: type to run code ” Then, enter values of ( j, r, b ) as ( 20, 5, 7 ) respectively to get the output ( b) WAP to read, display and save an image with a 'user defined name'. Task: Read an image, Display it, Save the image in a new name”B218018 .jpg’ MATLAB CODE: jrb = imread( 'jyoti.jpg' ); figure,imshow(jrb); imwrite(jrb, 'B218018.jpg' ); new_jrb = imread( 'B218018.jpg' ); figure, imshow(new_jrb) OUTPUT: ( c) WAP to subtract, add and scale the image. Task: (i) Read an image, Subtract 100 from it and display. (ii) Add 100 and display (iii) Multiply with 0.7 and display (iv) Use Subplot 2*2 MATLAB CODE: jrb = imread( 'jyoti.jpg' ) ; jrb1 = jrb - 100 ; jrb2 = jrb+100; jrb3 = jrb*0.7; subplot(2,2,1); imshow(jrb) ; title( 'original' ); subplot(2,2,2); imshow(jrb1) ; title( 'subtraction' ); subplot(2,2,3); imshow(jrb2); title( 'addition' ); subplot(2,2,4); imshow(jrb3); title( 'scaling' ); OUTPUT: ( d) WAP to perform RGB to gray scale and then to binary image. Use Subplot, display colour image, grayscale image, bina ry image in one figure. MATLAB CODE: jrb = imread( 'magic.jpg' ); subplot(2,2,1); title( 'original' ) imshow(jrb) rgb1 = rgb2gray(jrb); subplot(2,2,2); title( 'grayscale' ) imshow(rgb1) BW = im2bw(jrb,0.4); subplot(2,2,3); title( 'binary image' ) imshow(BW) OUTPUT: ( e) WAP to reshuffle the RGB components to create new color images. Use Subplot (2*2), original image, GRB, BGR, BRG MATLAB CODE: sampleImage = imread( 'magic.jpg' ); redCode = sampleImage(:, :, 1); greenCode = sampleImage(:, :, 2); blueCode = sampleImage(:, :, 3); subplot(2,2,1) imshow(sampleImage) title( 'RGB IMAGE' ) subplot(2,2,2) brgSample = cat(3, blueCode,redC ode, greenCode); imshow(brgSample) title( 'BRG IMAGE' ) subplot(2,2,3) grbSample = cat(3, greenCode,redCode, blueCode); imshow(grbSample) title( 'GRB IMAGE' ) subplot(2,2,4) bgrSample = cat(3, blueCode,greenCode,redCode); imshow(bgrSample) title( 'BGR IMAGE' ) OUTPUT: ( f) (i) WAP to Flip the image. (ii) WAP to Mirror the image. MATLAB CODE: jrb = imread( 'iiit_logo.jpg' ); subplot(2,2,1); imshow(jrb) title( 'ORIGINAL IMAGE' ) subplot(2,2,2); vertFlip_img = flip(jrb, 1); imshow(vertFlip_img); title( 'VERTICALLY FLIPPED IMAGE' ); subplot(2,2,3); mirror_img = flip(jrb,2); imshow(mirror_img); title( 'MIRRORED IMAGE' ) OUTPUT: ( g) WAP to partition the image in 4 equal parts. Use subplot to display the 4 parts in a single figure window. MATLAB CODE: jrb = imread( 'B218018.jpg' ); jrb1=jrb(1:size(jrb,1)/2,1:size(jrb,2)/2,:); jrb2=jrb(size(jrb,1)/2+1:size(jrb,1),1:size(jrb,2)/2,:); jrb3=jrb(1:size(jrb,1)/2,size(jrb,2)/2+1:size(jrb,2),:); jrb4=jrb(size(jrb,1)/2+1:size(jrb,1),size(jrb,2)/2+1:size (jrb,2),:); subplot(2,2,1); imshow(jrb1); subplot(2,2,2); imshow(jrb3); subplot(2,2,3); imshow(jrb2); subplot(2,2,4); imshow(jrb4); OUTPUT: SUBMITTED BY: JYOTI RANJAN BHOI BRANCH - ETC ID - B218018 EXPERIMENT 2 : IMAGE PROCESSING USING SIMULINK (2.1)( a) Read and display colour image using simulink block. SIMULINK DESIGN: RESULTS : (2.1)( b) Display each plane of the colour image. SIMULINK DESIGN: RESULTS : (2.2)( a) Convert RGB to Gray scale image using in - built block. SIMULINK DESIGN: RESULTS : (2.2)( b) Convert RGB to Gray scale image using user created function block. Y= 0.2989 * R + 0.5870 * G + 0.1140 * B SIMULATION DESIGN: MATLAB FUNCTION: function y = fcn( r,g,b) y = 0.298*r+ 0.5870*g+0.1140*b; RESULTS : (2.3) ( a) Complement of a Gray scale image using in - built block. SIMULINK DESIGN: RESULTS : (2.3) ( b) Complement of a Gray scale image using user created function block. SIMULATION DESIGN: MATLAB FUNCTION: function y = fcn(u) y = 255 - u; RESULTS : (2.4) Create a binary image from RGB image using mean as a threshold. SIMULATION DESIGN: RESULTS : (2.5) ( a) Read a Gray scale image. Add, subtract, and scale with a constant value with the image. Display the output. ( b) Using user defined functional block. SIMULATION DESIGN: MATLAB FUNCTION: function [y1,y2,y3]= fcn(u) y1=u+0.2; y2=u - 0.2; y3=u*1.5; INPUT IMAGE: RESULTS : SUBMITTED BY: JYOTI RANJAN BHOI BRANCH - ETC ID - B218018 EXPERIMENT 3 IMAGE QUANTIZATION, IMAGE RESAMPLING Exp 3.1: WAP for intensity level quantization of gray scale image. Explore Commands: multithresh(), imquantize(). Try for different levels of quantization, justify and analyze your output. MATLAB CODE: clc close all clear all jrb=imread( 'cameraman.tif' ); subplot(331) imshow(jrb); title( 'original image' ); level = multithresh(jrb); seg_jrb = imquantize(jrb,level); subplot(332) imshow(seg_jrb,[]) title( 'Image with 1 - level quantization' ); level = multithresh(jrb,3); seg_jrb = imquantize(jrb,level); subplot(333) imshow(seg_jrb,[]) title( 'Image with 3 - level quantization' ); level = multithresh(jrb,5); seg_jrb = imquantize(jrb,level); subplot(334) imshow(seg_jrb,[]) title( 'Image with 5 - level quantization' ); level = multithresh(jrb,7); seg_jrb = imquantize(jrb,level); subplot(335) imshow(seg_jrb,[]) title( 'Image with 7 - level quantization' ); OUTPUT: Exp 3.2: A. WAP to increase the size of image to double of its original using nearest neighbor interpolation method. B. WAP to reduce the size of image to half of its original using nearest neighbor interpolation method. Hint: Use inbuilt function imresize() MATLAB CODE: clc close all clear all I = imread( 'peppers.png' ); figure, imshow(I) title( 'original image' ); J = imresize(I, 2, 'nearest' ); figure, imshow(J) title( 'scaled image' ); J = imresize(I, 0.5, 'nearest' ); figure, imshow(J) title( 'reduced image' ); OUTPUT: Exp 3.3: WAP to increase the size of image to double of its original using replication method A.Use convolution method B.Use Mathematical formula MATLAB CODE: clc close all clear all jrb = imread( 'cameraman.tif' ); figure, imshow(jrb) title( 'original image' ); %% REPLICATION METHOD USING CONVOLUTION METHOD z=zeros(2*size(jrb,1),2*size(jrb,2)); for r=1:size(jrb,1) for c=1:size(jrb,2) z(2*r - 1,2*c - 1)=jrb(r,c); end end h=ones(2,2); new=conv2(z,h); figure, imshow(new,[]) title( 'scaled image using convolution method' ); %% REPLICATION METHOD USING MATHEMATICAL METHOD z2=zeros(2*size(jrb,1),2*size(jrb,2)); for r=1:size(jrb,1) for c=1:size(jrb,2) z2(2*r - 1,2*c - 1)=jrb(r,c); z2( 2*r,2*c - 1)=jrb(r,c); z2(2*r - 1,2*c)=jrb(r,c); z2(2*r,2*c)=jrb(r,c); end end figure, imshow(z2,[]) title( "scaled image using mathematical method" ); OUTPUT: