├── .gitattributes ├── kidney.tif ├── einstein.tif ├── blurry_moon.tif ├── einstein_orig.tif ├── mars_moon_phobos.tif ├── embedded_square_noisy_512.tif ├── set1q2.m ├── set1q3.m ├── set1q1.m ├── set1q4.m ├── set1q5.m ├── README.md ├── set1q7.m └── set1q6.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /kidney.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/kidney.tif -------------------------------------------------------------------------------- /einstein.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/einstein.tif -------------------------------------------------------------------------------- /blurry_moon.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/blurry_moon.tif -------------------------------------------------------------------------------- /einstein_orig.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/einstein_orig.tif -------------------------------------------------------------------------------- /mars_moon_phobos.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/mars_moon_phobos.tif -------------------------------------------------------------------------------- /embedded_square_noisy_512.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auggen21/image-processing-basics-matlab/HEAD/embedded_square_noisy_512.tif -------------------------------------------------------------------------------- /set1q2.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all; 3 | close all; 4 | a=imread('cameraman.tif'); 5 | j = imadjust(a,[0 1],[1 0]); 6 | figure; 7 | subplot(1,2,1); 8 | imshow(a);title('Original Image') 9 | subplot(1,2,2); 10 | imshow(j);title('Negative Image') -------------------------------------------------------------------------------- /set1q3.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | close all; 3 | i=imread('cameraman.tif'); 4 | for a=0:255 5 | b=(i==a); 6 | d(a+1)=sum(b(:)); 7 | end 8 | figure,subplot(2,1,1),bar(d) 9 | title('Histogram without using inbuilt function'),axis([0 300 0 2000]) 10 | subplot(2,1,2),imhist(i), 11 | title('Histogram using inbuilt function'),axis([0 300 0 2000]) 12 | 13 | 14 | -------------------------------------------------------------------------------- /set1q1.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all; 3 | close all; 4 | i=imread('cameraman.tif'); 5 | subplot(1,2,1),imshow(i),title('Original Image') 6 | details=imfinfo('cameraman.tif') 7 | a=details.FileSize; 8 | imwrite(i,'new.jpg'); 9 | new=imread('new.jpg'); 10 | subplot(1,2,2),imshow(new),title('Copied Image') 11 | newdetails=imfinfo('new.jpg') 12 | b=newdetails.FileSize; 13 | c=a/b; 14 | display('Compression ratio') 15 | display(c) -------------------------------------------------------------------------------- /set1q4.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | close all; 3 | im=imread('pout.tif'); 4 | s=0; 5 | [row,col]=size(im); 6 | enimg=zeros(row,col); 7 | for a=0:255 8 | b=(im==a); 9 | s=s+sum(b(:)); 10 | su(a+1)=sum(b(:)); 11 | out(a+1)=ceil(255*s/numel(im)); 12 | enimg=enimg+ out(a+1)*b; 13 | end 14 | l=uint8(enimg); 15 | figure,subplot(2,2,1),imshow(im),title('Original Image'); 16 | subplot(2,2,2),imhist(im),title('Histogram of original image') 17 | axis([0 300 0 4000]) 18 | subplot(2,2,3),imshow(l),title('After Histogram Equalization'); 19 | subplot(2,2,4),imhist(l),title('Histogram of histogram equalized image') 20 | axis([0 300 0 4000]) -------------------------------------------------------------------------------- /set1q5.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | close all; 3 | of=imread('embedded_square_noisy_512.tif'); 4 | f=double(of); 5 | ws=7; 6 | pd=(ws-1)/2; 7 | start=ws-pd; 8 | f=padarray(f,[pd pd]); 9 | [row,col]=size(f); 10 | for i=start:ws:row-pd 11 | for j=start:ws:col-pd 12 | im=f(i-pd:i+pd,j-pd:j+pd); 13 | s=0; 14 | enimg=zeros(ws,ws); 15 | for a=1:256 16 | b=(im==a); 17 | s=s+sum(b(:)); 18 | out(a)=ceil(255*s/(ws*ws)); 19 | enimg=enimg+ out(a)*b; 20 | end 21 | outres(i-start+1:i-start+ws,j-start+1:j-start+ws)=enimg; 22 | end 23 | end 24 | outres=uint8(outres); 25 | figure,subplot(1,2,1),imshow(of),title('Original Image'); 26 | subplot(1,2,2),imshow(outres),title('After Local Histogram Equalization'); 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # image processing basics matlab 2 | 3 | 1. Write MATLAB functions for the following: 4 | a. Read an image 5 | b. Copy the image into another file 6 | c. Get the image information 7 | d. Find the compression ratio for the copied image 8 | 2. Display the negative of an image using the MATLAB function imadjust. 9 | 3. Write an M-function for histogram plotting of an image 10 | 4. Write a MATLAB program (using an M-function) to perform histogram equalization. 11 | 5. Write an M-Function for performing local histogram equalization. 12 | 6. Develop programs for the following image enhancement operations. 13 | a. Brightness enhancement 14 | b. Contrast enhancement 15 | c. Complement of an image 16 | d. Bi-level or binary contrast enhancement 17 | e. Brightness slicing 18 | f. Low-pass filtering 19 | g. High-Pass filtering 20 | 7. Develop programs for the following geometrical transformations on an image 21 | a. Translation 22 | b. Rotation 23 | c. Scaling 24 | d. Skewing 25 | -------------------------------------------------------------------------------- /set1q7.m: -------------------------------------------------------------------------------- 1 | close all 2 | clear all; 3 | 4 | while 1 5 | ch=menu(' SELECT','1.SELECT IMAGE','2.TRANSLATION',' 3.ROTATION',' 4.SCALING',' 5. SKEWING',' 6.EXIT'); 6 | switch ch 7 | 8 | case 1 9 | i=input('Enter the image name:'); 10 | im=imread(i); 11 | im=double(im); 12 | [row,col]=size(im); 13 | figure,imshow(uint8(im)),title('Original Image') 14 | 15 | %Translation 16 | case 2 17 | tx=input('Enter the translation in X direction:'); 18 | ty=input('Enter the translation in Y direction:'); 19 | T=[tx;ty]; 20 | out1=zeros(row+tx,col+ty); 21 | for i=1:row 22 | for j=1:col 23 | P=[i;j]; 24 | TP=ceil(T+P); 25 | out1(TP(1),TP(2))=im(i,j); 26 | end 27 | end 28 | figure,imshow(uint8(out1)),title(['Translated Image with tx=',num2str(tx),',ty=',num2str(ty)]) 29 | 30 | %Rotation 31 | case 3 32 | degree=input('Enter the rotation angle in degree:'); 33 | angle=degree*pi/180; 34 | R=[cos(angle) -sin(angle); sin(angle) cos(angle)]; 35 | for i=1:row 36 | for j=1:col 37 | P=[i;j]; 38 | RP=R*P; 39 | RP=round(RP); 40 | first(i,j)=RP(1); 41 | second(i,j)=RP(2); 42 | end 43 | end 44 | fmin=min(first(:)); 45 | smin=min(second(:)); 46 | first=first-fmin+2; 47 | second=second-smin+2; 48 | outsize1=max(first(:)); 49 | outsize2=max(second(:)); 50 | out2=256*ones(outsize1+1,outsize2+1); 51 | 52 | for i=1:row 53 | for j=1:col 54 | a=first(i,j); 55 | b=second(i,j); 56 | out2(a,b)=im(i,j); 57 | out2(a-1,b)=im(i,j); 58 | out2(a+1,b)=im(i,j); 59 | out2(a,b-1)=im(i,j); 60 | out2(a,b+1)=im(i,j); 61 | end 62 | end 63 | figure,imshow(uint8(out2)),title(['Rotated Image with angle=',num2str(degree)]); 64 | 65 | case 4 66 | %Scaling 67 | 68 | sx=input('Enter the scaling parameter in x:'); 69 | sy=input('Enter the scaling parameter in y:'); 70 | S=[sx 0;0 sy]; 71 | out3=256*ones(ceil(sx*row),ceil(sy*col)); 72 | for i=1:row 73 | for j=1:col 74 | P=[i;j]; 75 | NS=ceil(S*P); 76 | out3(NS(1),NS(2))=im(i,j); 77 | end 78 | end 79 | 80 | figure,imshow(uint8(out3)),title(['Scaled Image sx=',num2str(sx),',sy=',num2str(sy)]); 81 | 82 | 83 | case 5 84 | %skewing 85 | skx=input('Enter the skewing parameter in x:'); 86 | sky=input('Enter the skewing parameter in y:'); 87 | SK=[1 skx;sky 1]; 88 | out4=256*ones(row+ceil(skx*col),col+ceil(sky*row)); 89 | for i=1:row 90 | for j=1:col 91 | P=[i;j]; 92 | NSK=ceil(SK*P); 93 | out4(NSK(1),NSK(2))=im(i,j); 94 | end 95 | end 96 | figure,imshow(uint8(out4)),title(['Skwed Image skx=',num2str(skx),',sky=',num2str(sky)]); 97 | case 6 98 | close all 99 | break; 100 | end 101 | end 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /set1q6.m: -------------------------------------------------------------------------------- 1 | close all 2 | clear all 3 | im=imread('einstein.tif'); 4 | [row,col]=size(im); 5 | a=double(im); 6 | figure, subplot(1,3,1), imshow(im),title ('original image') 7 | 8 | % Brightness 9 | b=im+100; 10 | b=uint8(b); 11 | subplot(1,3,2),imshow(b),title ('Brightness Enhanced') 12 | 13 | %contrast 14 | alpha=.1; 15 | beta=2; 16 | gamma=.1; 17 | low=80; 18 | high=170; 19 | out1=alpha*a.*(at); 36 | subplot(1,2,2),imshow(e),title ('Binary Image Enhancement') 37 | 38 | %brightness slicing 39 | 40 | im4=imread('kidney.tif'); 41 | figure, subplot(1,3,1), imshow(im4),title ('original image') 42 | lo=180; 43 | hi=250; 44 | fst=(lo