# matlab experiment of digital image processing

Foreword: as an image algorithm siege lion, in the second semester of junior year in 2014, a dark green digital image processing (English version of Gonzalez) appeared in front of his desk. An unexpected door was opened by chance, and thus an indissoluble bond was formed. In those days, I kept searching for codes on the Internet, and I submitted my homework in less than 20 minutes after I got on the computer. I had already gone with the past years. After three years of smoking and drinking and two years of soy sauce workers, I just feel that my brain is becoming more and more inadequate. This time, I am determined to go back to the furnace and rebuild it. I hope I can open up my mind through consolidating the foundation, saying nothing more, and start classes!
----2020-7-7

## Experiment 9 image edge detection

1, Experimental purpose
Through this experiment, students can master the basic methods of image edge detection and deepen their understanding of image segmentation.
2, Experimental principle
This experiment is based on the theory of image segmentation in the course of digital image processing.
Preparatory knowledge of this experiment: Chapter 3 spatial image enhancement, Chapter 10 image segmentation on image sharpening and edge detection methods. The key points are as follows:
1. The significance of image sharpening, among which the key operators are:
a) Prewitt operator
b) Sobel operator
c) LoG Operator
2. The significance of image segmentation, including key operators: prewitt operator and sobel operator
3. Image edge detection technology

3, Experiment content
(1) Image sharpening
Read Lena_ Gray TIF image,
(1) Use prewitt operator to sharpen the image, display the original image and sharpened image on the same screen, and explain the results.

```clc
[H,W]=size(I);
M=double(I);
J=M;
for i=2:H-1
for j=2:W-1
J(i,j)=abs(M(i-1,j+1)-M(i-1,j-1)+M(i,j+1)-M(i,j-1)+M(i+1,j+1)-M(i+1,j-1))+abs(M(i+1,j-1)-M(i-1,j-1)+M(i+1,j)-M(i-1,j)+M(i+1,j+1)-M(i-1,j+1));
end
end
subplot(1,2,1);imshow(I);title('Original drawing');
subplot(1,2,2);imshow(uint8(J));title('Prewitt After treatment');
``` (2) Use sobel operator to sharpen the image, display the original image and sharpened image on the same screen, and explain the results.

```clc
[H,W]=size(I);
M=double(I);
J=M;
for i=2:H-1
for j=2:W-1
J(i,j)=abs(M(i-1,j+1)-M(i-1,j-1)+2*M(i,j+1)-2*M(i,j-1)+M(i+1,j+1)-M(i+1,j-1))+abs(M(i-1,j-1)-M(i+1,j-1)+2*M(i-1,j)-2*M(i+1,j)+M(i-1,j+1)-M(i+1,j+1));
end
end
subplot(1,2,1);imshow(I);title('Original drawing');
subplot(1,2,2);imshow(uint8(J));title('Sobel After treatment');
``` (3) Use LoG operator to sharpen the image, display the original image and sharpened image on the same screen, and explain the results.

```clc
[H,W]=size(I);
M=double(I);
J=M;
for i=2:H-1
for j=2:W-1
J(i,j)=4*M(i,j)-[M(i+1,j)+M(i-1,j)+M(i,j+1)+M(i,j-1)];
end
end
subplot(1,2,1);imshow(I);title('Original drawing');
subplot(1,2,2);imshow(uint8(J));title('Sharpened image');
``` (4) The advantages and disadvantages of the three operators are illustrated by comparing the sharpening results above.

(2) Image edge detection
Read house TIF image,
(1) A suitable operator is designed to detect the horizontal edge of the image, display the original image and the edge image on the same screen, and interpret the results.

```clc
subplot(121)
imshow(f)
title('image')
[ gb,t2]=edge(f,'sobel','horizontal');%apply edge Function pair image f Extract horizontal edges
subplot(122)
imshow(gb)
title('Horizontal edge of image')
``` (2) A suitable operator is designed to detect the longitudinal edge of the image. The original image and the edge image are displayed on the same screen, and the results are explained.

```clc
subplot(121)
imshow(f)
title('image')
[gv,t1]=edge(f,'sobel','vertical');%apply edge Function pair image f Extract vertical edges
subplot(122)
imshow(gv)
title('Vertical edge of image')
``` (3) Superimpose the above two edge images to try to explain the significance of the results.

(3) Image segmentation
Read rice TIF image,
(1) The prewitt operator is used to segment the image, the original image and the segmented image are displayed on the same screen, and the results are explained.

```clc
subplot(121)
imshow(f)
title('image')
f1=edge(f,'prewitt');
subplot(122)
imshow(f1)
title('After image processing')
``` (2) sobel operator is used to segment the image, the original image and the segmented image are displayed on the same screen, and the results are explained.

```clc
subplot(121)
imshow(f)
title('image')
f1=edge(f, 'sobel');
subplot(122)
imshow(f1)
title('After image processing')
``` 4, Experimental methods and procedures
1. Complete the above experiments in sequence
2. According to the requirements of experiment content, analyze and program, arrange the program and experiment results into word documents, analyze the results, and prepare the experiment report.

5, Test report requirements
1. The experiment was completed by students alone.
2. Each experiment was reported in a uniform format.
The contents of the experiment report include: experiment requirements, experiment items, typical program flow chart, program list, data results, analysis and discussion.

Posted by goocharlton on Tue, 31 May 2022 12:55:00 +0530