Offline Notepad View raw

Shared snapshot

DIP

Image resize img1=imread('C:\Users\vignan\Documents\221fa04719\tiger.jpg'); img2=imresize(img1, size(100,100)); imshow(img2);

Arithematic operations image1= imread("bts7.jpeg"); image2=imread("bts8.jpeg"); addsize= imresize(image2,[size(image1,1),size(image1,2)]); add= image1 + addsize; imshow(add); subtract= image1 - addsize; imshow(subtract); mul= image1 .* addsize; imshow(mul); div= image1 ./ addsize; imshow(div);

Operations img1=imread('C:\Users\vignan\Downloads\squarrell.jpg'); img2=imread('C:\Users\vignan\Downloads\flower.jpg'); img2=imresize(img1,[size(100,100)]); img1=im2bw(img1); img2=im2bw(img2); img3=img1 & img2; img4=img1 | img2; img5=xor(img1,img2); img6=~img1; subplot(141),imshow(img3),title('logical and'); subplot(142),imshow(img4),title('logical or'); subplot(143),imshow(img5),title('logical xor'); subplot(144),imshow(img6),title('logical not');

Negative image skl=imread('C:\Users\vignan\Downloads\flowers1.jpg'); subplot(1,2,1); imshow(skl); title('Original image'); L=2^8; neg=(L-1)-skl; subplot(1,2,2); imshow(neg); title('Negative Image');

Log transformation img=imread('C:\Users\vignan\Downloads\prabhas photos 13.jpg'); r=double(img); C=1; S=Clog(1+r); T=255/(Clog(256)); B=uint8(T*S); figure,imshow(B); title('Log Transformation');

Power log transformation img=imread('C:\Users\vignan\Downloads\mickey.jpg'); r=double(img); G=3; C=1; S=C*(r.^G); T=255/(C*(255.^G)); O=uint8(T.*S); figure, imshow(O); title('Power Law Transformation');

Gray level slicing i=imread('C:\Users\vignan\Downloads\cutie.jpg'); j=double(i); k=double(i); [row,col]=size(j); T1=input('Enter the Lowest threshold value:'); T2=input('Enter the Highest threshold value:'); for x=1:row for y=1:col if((j(x,y)>T1)&&(j(x,y)<T2)) j(x,y)=i(x,y); k(x,y)=255; else j(x,y)=0; k(x,y)=0; end end end subplot(311),imshow(i),title('Originalimage') subplot(312),imshow(uint8(j)),title('Graylevel slicing with background') subplot(313),imshow(uint8(k)),title('Graylevel slicing without background')

Histogram equalization I= imread("bts7.jpeg"); subplot(2,2,1), imshow(I),title("Original Image"); subplot(2,2,2),imhist(I); J= histeq(I); subplot(2,2,3),imshow(J), title("Histogram Equilised Image"); subplot(2,2,4),imhist(J);

Gaussian low pass filter image=imread(' C:\Users\vignan\Documents\MATLAB\img1.jpeg'); gray_image=rgb2gray(image); h_laplacian=fspecial('laplacian',0.2); lpf_laplacian=imfilter(gray_image,h_laplacian); h_gaussian=fspecial('gaussian',[5,5],1); lpf_gaussian=imfilter(gray_image,h_gaussian); figure; subplot(1,3,1),imshow(gray_image),title('original image'); subplot(1,3,2),imshow(lpf_average),title('Low-pass filtered(Average)'); subplot(1,3,3),imshow(lpf_gaussian),title('Low-pass Filtered(Gaussian)');

Gaussian high pass filter image = imread('C:\Users\vignan\Pictures\log.jpg'); h_laplacian = fspecial('laplacian', 0.2); hpf_laplacian = imfilter(gray_image, h_laplacian); h_gaussian = fspecial('gaussian', [5, 5], 1); lpf_image = imfilter(gray_image, h_gaussian); hpf_subtract = gray_image - lpf_image; figure; subplot(1, 3, 1), imshow(gray_image), title('Original Image'); subplot(1, 3, 2), imshow(hpf_laplacian, []), title('High-Pass Filtered (Laplacian)'); subplot(1, 3, 3), imshow(hpf_subtract, []), title('High-Pass Filtered (Subtract)');

Gaussian lpf hpf using frequency domain img=imread('C:\Users\vignan\Documents\MATLAB\shin.jpg'); img=double(rgb2gray(img)); F=fft2(img); Fshift=fftshift(F); [rows,cols]=size(img); crow=round(rows/2); ccol=round(cols/2); radius=30; [x,y]=meshgrid(1:cols,1:rows); LPF=sqrt((x-ccol).^2+(y-crow).^2) <=radius; F_LPF=Fshift.*LPF; img_LPF=real(ifft2(ifftshift(F_LPF))); HPF=double(sqrt((x-ccol).^2+(y-crow).^2)>radius); F_HPF=Fshift.*HPF; img_HPF=real(ifft2(ifftshift(F_HPF))); figure; subplot(1,3,1),imshow(img,[]),title('Original image'); subplot(1,3,2),imshow(img_LPF,[]),title('Low-Pass Filtered image'); subplot(1,3,3),imshow(img_HPF,[]),title('High-pass Filtered Image');

Edge detection I = rgb2gray(imread('C:\Users\vignan\Documents\leena1.jpg')); subplot(2, 2, 1), imshow(I); title('Gray Scale Image'); % Sobel Edge Detection J = edge(I, 'Sobel'); subplot(2, 2, 2), imshow(J); title('Sobel'); % Prewitt Edge detection K = edge(I, 'Prewitt'); subplot(2, 2, 3), imshow(K); title('Prewitt'); % Robert Edge Detection L = edge(I, 'Roberts'); subplot(2, 2, 4), imshow(L); title('Robert');

Sobel edge detection k=imread('C:\Users\vignan\Documents\leena1.jpg'); k=rgb2gray(k); k1=double(k); p_msk=[-1 0 1; -2 0 2; -1 0 1]; kx=conv2(k1, p_msk, 'same'); ky=conv2(k1, p_msk', 'same'); subplot (2,2,1); imshow(k); subplot (2,2,2); imshow(kx); subplot (2,2,3); imshow(ky);

Perwitt edge detection k=imread('C:\Users\vignan\Documents\leena1.jpg'); k=rgb2gray(k); k1=double(k); p_msk=[-1 0 1; -1 0 1; -1 0 1]; kx=conv2(k1, p_msk, 'same'); ky=conv2(k1, p_msk', 'same'); subplot (2,2,1); imshow(k); subplot (2,2,2); imshow(kx); subplot (2,2,3); imshow(ky);

Line detection k=imread('C:\Users\vignan\Downloads\IMG-20240221-WA0004.jpg');
k=im2bw(k); w1=1/3*[1 0 -1;1 0 -1;1 0 -1]; g=(imfilter(double(k),w1)); g(g<1)=0; subplot (2,2,1); imshow(g); title('Horizontal line'); w1=1/3*[1 1 1;0 0 0;-1 -1 -1]; g=(imfilter(double(k),w1)); g(g<1)=0; subplot (2,2,2); imshow(g); title('Vertical line'); w1=1/3*[-1 -1 0;-1 0 1;0 1 1]; g=(imfilter(double(k),w1)); g(g<1)=0; subplot (2,2,3); imshow(g); title('+45 Diagonal line'); w1=1/3*[0 -1 -1;1 0 -1;1 1 0]; g=(imfilter(double(k),w1)); g(g<1)=0; subplot (2,2,4); imshow(g); title(‘-45 diagonal’);

Image segmentation I=imread('C:\Users\vignan\Downloads\cam1.tif'); imshow(I); title('Original Image'); mask=false(size(I)); mask(170,70)=true; W=graydiffweight(I,mask,'GrayDifferenceCutoff',25); thresh=0.01; [BW,D]=imsegfmm(W,mask,thresh); figure; imshow(BW); title('Segmented Image');

Morphological Thinning and Thickening I=imread("bts8.jpeg"); subplot(2,2,1),imshow(I),title("Original Image"); binaryImg= im2bw(I); subplot(2,2,2),imshow(binaryImg),title("Binary Image"); I_thin= bwmorph(binaryImg,'thin',5); subplot(2,2,3),imshow(I_thin),title("Morphological Thinned Image"); I_thick= bwmorph(binaryImg, 'thick',5); subplot(2,2,4),imshow(I_thick),title("Morphological Thicked Image");

Morphological operations I=imread("bts8.jpeg"); subplot(2,3,1),imshow(I),title("Original Image"); SE= strel('line',7,7); I_dil= imdilate(I,SE); subplot(2,3,2),imshow(I_dil),title("Dilated Image"); I_erode= imerode(I,SE); subplot(2,3,3),imshow(I_erode),title("Eroded Image"); I_open= imopen(I,SE); subplot(2,3,4),imshow(I_open),title("Opened Image"); I_close= imclose(I,SE); subplot(2,3,5),imshow(I_close),title("Closed Image");