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

Case Analysis of Color Space in OpenCV

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "case analysis of color space in OpenCV". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "case analysis of color space in OpenCV".

1 different color spaces

In this section, we will introduce some important color spaces used in computer vision. We don't describe the theory behind them, we just need to know how to use them.

The conversion of OpenCV color space is very simple, the imread function reads the image and loads it in BGR format, and the cvtColor function converts between different color spaces.

The following image is a cube image under different lighting. The first image was taken under sunny outdoor conditions, while the second image was taken under normal indoor light conditions.

1.1RGB color space

RGB color space has the following properties: 1. It is an additive color space in which the color is obtained by a linear combination of red R, green G and blue B. 1. The illumination of the object will affect the values of each channel in the color space, and the three color channels are related. Let's divide the above image into Rpene G and B components and observe them to gain a deeper understanding of the color space.

As you can see from the image below, if you look at the blue channel, you can see that the blue and white parts of the Rubik's cube in the second image look similar in indoor lighting, but there is a significant difference in the first image. This non-uniformity makes color-based segmentation very difficult in this color space. In addition, there is an overall difference between the values of the two images. Therefore, there are some problems in RGB color space, such as uneven distribution of color values and mixing of chromaticity and luminance.

1.2 Lab color space

Similar to RGB space, Lab also has three image channels.

L: luminance channel, table brightness.

A: color channel a, representing colors from green to magenta.

B: color channel b, representing colors from blue to yellow.

The Lab color space is completely different from the RGB color space. In RGB color space, color information is divided into three channels, but the same three channels also contain luminance information. On the other hand, in Lab color space, L channel is independent of color information and only contains luminance information. The other two channels encode colors.

Lab color space also has the following characteristics: 1. The perceptual uniform color space is similar to how we perceive color. 1. Independent of the device (capture or display). 1. Widely used in Adobe Photoshop. 1. The complex transformation equation is related to the RGB color space. The image is read in OpenCV and converted to Lab space image. The result is as follows:

It can be clearly seen from the picture that the change of light mainly affects the l component. 1. The an and b components containing color information do not change greatly under the change of light. 1. The corresponding values of green, orange, and red (which are the main colors of channel a) do not change in channel b, and similarly, blue and yellow (they are the main colors of channel b) do not change in channel a. # #

1.3 YCrCb color space

YCrCb color space is derived from RGB color space and has the following three components.

Channel Y: the luminance or luminance component obtained from RGB after gamma correction.

Channel Cr:Cr=R-Y (the distance between the red component and the luminance component Y).

Channel Cb:Cb=B-Y (the distance between the blue component and the luminance component Y).

This color space has the following properties. 1. The luminance and chrominance components are divided into different channels. 1. Mainly used for compression of television transmission (Cr and Cb components). 1. Depends on the equipment. The two images in the YCrCb color space that are divided into its channels are as follows:

For illuminance changes, LAB can be similarly observed for intensity and color components. Compared with LAB, the perceptual difference between red and orange in outdoor images is smaller. White has changed in all three components.

1.4 HSV color space

The HSV color space has the following three components:

H hue, S saturation, V lightness.

The biggest feature of HSV is that it uses only one channel to describe the color (H), which makes it very intuitive to specify a color. But the HSV color depends on the device.

The S and V components of the two images are shown below.

As you can see from the following picture

The H component is very similar in the two images, which indicates that the color information is complete even under the change of illumination.

The S component in the two images is also very similar.

The V component represents brightness, so it changes due to changes in lighting.

There is a huge difference between the values of red outdoor and indoor images. This is because the H value represents the starting angle in red in terms of angle. Therefore, it may take the value between the angle [300360] and [0jue 60].

2 how to use these color spaces for segmentation

Now that we know the different color spaces, let's first try to use them to detect the green in the Rubik's cube.

2.1 get the color value of a specific color

Find the approximate range of green values for each color space. By getting the values of all color spaces for each pixel, as follows:

2.2 apply Segmentation threshold

It is just that the inRange function is used to select the appropriate threshold for image segmentation. In practice, the general effect of image segmentation by color is very poor. It is not recommended to use it, just learn about it.

Thank you for your reading, the above is the content of "case analysis of color space in OpenCV". After the study of this article, I believe you have a deeper understanding of the problem of case analysis of color space in OpenCV, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report