In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Python how to achieve RGB and other pictures of the image interpolation algorithm", in the daily operation, I believe that many people in the Python how to achieve the image interpolation algorithm of RGB and other pictures have doubts, editor consulted all kinds of data, sorted out a simple and easy to use method of operation, hope to answer the "Python how to achieve RGB and other pictures of the image interpolation algorithm" of the doubt to help! Next, please follow the editor to study!
RGB Color Image and Array understanding
For the three-dimensional array formed by reading this picture into the array, I just understood it for a long time. I looked for the information of the boss on the Internet and so on, and then slowly formed my own understanding. The bosses all have different opinions and have taken a lot of detours. Here, my understanding is written down: first, it is convenient to learn and check it later; second, it is convenient for beginners like me to understand.
Without saying much first, let's go straight to the picture:
Here I directly draw the number of three channels of the color picture into a three-digit picture to show my own understanding. Color pictures are three channels, respectively R, G, B, the overlap of these three channels, by adjusting the brightness of the gray value of each channel, thus forming a colorful color world!
The red area is channel 0 (R), and so on, channel 1 (G), channel 2 (B). The array read back is a three-dimensional array, which is divided into many two-dimensional matrices, each of which has three columns (three channels). The number of I (high h) in the image above indicates how many two-dimensional arrays there are in the three-dimensional array and how many j (width h) there are, which means how many rows there are in the two-dimensional array, the number of channels k represents the number of channels, and the color image has three channels, so k is a fixed value of 3.
How to understand the values in the array?
Insert a picture of me as a soul painter to illustrate it (I can't help but shed tears in silence)
The left side of the above picture shows what a picture looks like when it is read into an array (hypothetical). The lines of different colors represent the pictures of different channels, and then stack the pictures in the three channels like the picture above to form this three-dimensional space map.
So much for the understanding of RGB images. I hope it can help beginners like me not to take detours.
The coordinate of the picture to it
To ask how this formula came from, the first one can be calculated proportionally according to the position of the enlarged pixels, and the second formula has not yet figured out how to calculate it. If only a boss had pointed it out to me.
There is an passed-in parameter in the code that specifies which alignment to use align = left, which is centered on its center by default.
Left align src_X = dst_X* (src_Width/dst_Width) src_Y = dst_Y* (src_Height/dst_Height)
The src_X here means that the point on the target image is mapped to the x coordinate point on the original image, and similarly, src_Y is mapped to the y coordinate point on the original image.
Dst_X represents the x-coordinate of the target image, and dst_Y represents the y-coordinate of the target image.
Center alignment src_X = (dst_X+0.5) * (src_Width/dst_Width)-0.5src_Y = (dst_Y+0.5) * (src_Height/dst_Height)-0.5
The src_X here means that the point on the target image is mapped to the x coordinate point on the original image, and similarly, src_Y is mapped to the y coordinate point on the original image.
Dst_X represents the x-coordinate of the target image, and dst_Y represents the y-coordinate of the target image.
Proximity interpolation algorithm
The nearest neighbor interpolation algorithm is the simplest. The coordinate point we have calculated is iMagazine j, which is rounded by round function to get the proximity value of img [iMagnej] this pixel (is a pixel value).
It can be seen in this picture that point An is the position on which the target image is mapped to the original image, the whole background is the original image, and the four points Q1, Q2, Q3 and Q4 in the picture are the four nearest pixels of point A.
The code of the nearest neighbor interpolation algorithm is the simplest, but the enlarged image is the worst. Let's take a look at the code implementation:
Def nearest_inter (self): "" nearest neighbor interpolation "" new_img = np.zeros ((self.goal_h, self.goal_w, self.goal_channel), dtype=np.uint8) for i in range (0, new_img.shape [0]): for j in range (0, new_img.shape [1]): src_i, src_j = self.convert2src_axes (I) J) new_img [I, j] = self.img [round (src_i), round (src_j)] return new_ IMG linear interpolation
To put it bluntly, the linear interpolation formula is the parametric equation form of the straight line in our mathematics. We know that two points can determine a straight line, but in the determined line, how can we determine a point in the straight line, so that we can establish the linear equation of the two points according to the relationship between the two parallel lines. Look at the picture below.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.