“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

preface

Hello! Friend!!!

Thank you very much for reading haihong’s article, if there are any mistakes in the article, please point out ~

 

Self-introduction ଘ(੭, ᵕ)੭

Nickname: Haihong

Tag: programmer monkey | C++ contestant | student

Introduction: because of C language to get acquainted with programming, then transferred to the computer major, had the honor to get some national awards, provincial awards… Has been confirmed. Currently learning C++/Linux/Python

Learning experience: solid foundation + more notes + more code + more thinking + learn English well!

MATLAB- Digital image processing sampling

1. After the installation of MATLAB software, click in and the following interface will appear: the blank area on the right (with fx) is the area where we write code. The working area on the left is the area where we write code2. Understand sampling First, we need to know what sampling is. Sampling: the images we obtain are generally analog images, which need to be digitized for computer processing. The role of sampling is to convert analog images into digital images. Generally speaking, the larger the sampling interval, the less pixels, the lower spatial resolution, poor quality, Mosaic effect occurs in serious cases; The smaller the sampling interval is, the more pixels, the higher the spatial resolution, the better the image quality, but the large amount of data.

Simply put, sampling is to digitize the image, the more digital features collected, the more realistic the image displayed on the computer.

First prepare an image, then Enter the code area to write the following code, press Enter, you will get the following result

T =imread('t1.jpg') % Read image T1 = rGB2gray (t) % Grayscale image T2 = T1 (1:4:end,1:4:end) % Sample imshow(T2) % to display on screenCopy the code

As I have just started to contact MATLAB and image processing, there are many places are still unclear. Let me tell you about the pit I stepped on.

  1. The line break in the MATLAB code area is: Shift +Enter
  2. There are two kinds of path of picture, one is relative path, the other is absolute path. The relative path is a path in the left workbench. We save the image here. When writing the code, we can use the name of the image as the path (as shown in the picture below, we can save it directly under the bin directory). The second way is to input the picture in the computer save path, this is easy to find, directly in the file there
  3. MATLAB only opens one window by default. If there are two imshows, only the content of the first imshow will appear. If you want more than one window, use figure.
  4. T2 = T1 (1:4:end,1:4:end) % Sample =t1(1:4:end,1:4:end) %
  5. One might ask, why grayscale the image in the first place? R G B.’t =imread(‘t1.jpg’) R G B.’t =imread(‘t1.jpg’)

T2 =t(1:4:end,1:4:end) imshow(T2) ‘so if you want to get a picture, you must first perform grayscale processing. (Here our image processing is to read the image data first, the read data is in the form of matrix, the value of the matrix is gray value, 0~ 255, there is no color, so when the color picture comes in, the system will read the gray value of r, G and B channels respectively, which forms three pictures.)

Complete code and renderings:

T =imread('t1.jpg') T1 =rgb2gray(t) imshow(T1),title(' original image ') % The original image needs to be converted to grayscale image t2= T1 (1:2:end,1:2:end) T3 = T1 (1:4:end,1:4:end) T4 = t1 (1:8: end, 1:8: end) t5 = t1 (1:16: end, 1:16: end) figure, subplot (2, 2, 1), imshow (t2), title (' 2-1 sampling) ,2,2 subplot (2), imshow (t3), title (' 1:4 sampling) subplot (2, 2, 3), imshow (t4), title (' 1:8 sampling) Subplot (2, 2, 4-trichlorobenzene), imshow (t5), title (' 1:16 sampling)Copy the code