Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read pictures and perform simple operations in Matlab

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to read pictures and carry out simple operations in Matlab, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

01

-

The use of Matlab

When we open the software, we will see the following interface, in which we have a brief introduction to the functions of each area. This occupies the largest area and is often the area with the lowest utilization rate in the development process.

To create a new project, we need to click the yellow plus sign "New" in the upper left corner of the interface, and you can select the file you want to create in the drop-down menu. When writing programs, we most often use .m files, and we can select the first and second options of the drop-down menu to create blank text. In the text, you can write programs just like writing C language.

02

-

Show a picture

After creating the .m file, we need to put the image we want to read under the work path. Although you don't have to put it in, Xiao Xin suggests that good programming habits should start bit by bit, and it's a good habit to put all files belonging to a project in a large folder. After all, when we don't know when we might delete some pictures or unused files, we will delete the files needed by other programs, causing an error the next time the program runs. Write down the code to read the image in the file.

Image = imread ('xiaobai.jpg')

Imshow (image)

Through the imread () function to read the image, you can also use the path where the picture is located to load the picture, so that you can load the picture under different paths. Then use the imshow () function to display the picture. These two functions are easy to remember, and the meaning can be known literally. Below, by clicking on the green triangle above to run the program, we can see Xiao Xin's cute photo.

From the data space on the right, we can see that the image variable is a 1024-1024-3 matrix data. It shows that our image has 1024 pixels, and the following three instructions are a color picture, which represents the data of the three channels of RGB. We extract data from three color channels respectively.

Image_R=image (:,:, 1); # read the first layer of data in the matrix

Image_G=image (:,)

Image_B=image (:, 3)

Figure (1) # create a dialog box for image display

Subplot, imshow (image_R); # divides the dialog box into 2 parts and displays the image in the first part

Subplot (2 and 2), imshow (image_G)

Subplot (2, 2, 3), imshow (image_B)

Subplot (2, 2, 4), imshow (image)

The comments of the code are relatively clear, running the program can see our carefree results of different color channels of Xiao Xin.

Curious friends will certainly ask why the color of each channel is black and white. Because Xiao Xin took out each channel separately, he programmed a black-and-white picture. If we want to display the color of each channel, we only need to set the other channels outside the red channel to zero to get the image of the corresponding color channel.

We sometimes need to use gray image to reduce the amount of data of the original image, we can use the rgb2gray () function to achieve the conversion of color image to gray image.

Image = imread ('xiaobai.jpg')

Image_g = rgb2gray (image); # Image graying

Imshow (image_g)

The color of the converted image is different from that of each channel.

We can save the generated gray image. When saving, we can choose different paths and formats according to our needs. Here Xiao Xin chooses the png format and stores it in the current workspace.

Imwrite (image_g,'new_xiaobai.png')

Seeing the generated new_xiaobai.png in the current workspace proves that the picture was saved successfully.

Thank you for reading this article carefully. I hope the article "how to read pictures and perform simple operations in Matlab" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report