First, what is image processing?
The image processing (image processing), image analyzed by a computer to achieve the desired technical result. Also known as image processing. Generally refers to image processing of digital image processing. Digital image refers to an industrial cameras, camcorders, scanners and other imaging devices obtained through the two-dimensional array of a large element of the array is called a pixel, which value is called gray value. Image processing techniques typically include image compression, enhancement and restoration, matching, and describes the identification of three parts.
Second, the common color space description:
RGB:
RGB (Red Red, Green Green, Blue blue), the color space of the human eye to identify defined, can be used to represent most of the colors, the image processing is the most basic, most commonly, hardware-oriented color space, is a . seed light mixing system
RGB color model is represented by a point in three-dimensional color space, each point has three components, respectively to the red, green, and blue luminance values
in a cube in the RGB model,
[1] - origin corresponding color is black, its three component values of 0;
[2] - from the origin of the color corresponding to the vertex farthest white, three component values are 1.
[3] - gray from black to white these values are distributed over two points of connection, the broken line is called the line of grays.
[4] - the remaining points corresponding to different color cube, i.e. the three primary colors, red, green, blue and mixed color of yellow, magenta ,blue.
HSI:
HSI color space model can be used to describe a cone, clearly showed hue (Hue), saturation changes case (Saturation, Chroma) and brightness (Intensity, Brightness) a.
Hue H (Hue) - represents the phase angle of the color red, green, and blue, respectively, separated by 120 degrees; 180 degrees respectively complementary chromatic aberration, i.e., color category.
Saturation S (Saturation) - or the purity of the color intensity expressed as the ratio between the maximum and the purity of the selected color purity of the color, range: [0, 1], i.e., the degree of color depth.
Luminance I (Intensity) - represents the brightness of color, usually a percentage to 100% (white) to 0% (black) to measure (the human eye is sensitive to luminance).
Three, OpenCV image processing foundation
1, image color space conversion
cv2.cvtColor(src,code,dst=None,dstCn=None)
- src: image color space conversion
- code: image conversion mode
mode | effect |
---|---|
cv2.COLOR_BGR2GRAY | BGR turn gray |
cv2.COLOR_BGR2HSV | BGR turn HSV |
cv2.COLOR_HSV2BGR | HSV turn BGR |
cv2.COLOR_BGR2RGB | BGR to RGB |
cv2.COLOR_RGB2BGR | RGB to BGR |
import cv2
imgBGR = cv2.imread("first.jpg",cv2.IMREAD_COLOR)
imgGRAY = cv2.cvtColor(imgBGR,cv2.COLOR_BGR2GRAY)
imgHSV = cv2.cvtColor(imgBGR,cv2.COLOR_BGR2HSV)
imgRGB = cv2.cvtColor(imgBGR,cv2.COLOR_BGR2RGB)
cv2.imshow("GRAY",imgGRAY)
cv2.imshow("BGR",imgBGR)
cv2.imshow("RGB",imgRGB)
cv2.imshow("HSV",imgHSV)
cv2.waitKey()
cv2.destroyAllWindows()
2, the image binarization:
Threshold:
threshold means that limit, so the threshold value called the critical value, refer to the minimum value or the maximum value of an effect that can be produced
simply is higher than the threshold value takes the maximum value is below the threshold value takes a minimum value (or the special value)
Thresh, DST = threshold (the src, Thresh, MAXVAL, type, DST = None)
- src: image to be processed
- thresh: Threshold
- maxval: higher than the highest threshold value becomes the
- type: division when using and what type of algorithm, common value of 0 (cv2.THRESH_BINARY)
Accepted values:
- thresh: Threshold
- Binarized image: dst
import cv2
img = cv2.imread("first.jpg",cv2.IMREAD_UNCHANGED)
retavel , dst = cv2.threshold(img,100,255,cv2.THRESH_BINARY)
print("阈值",retavel)
cv2.imshow("threshold",dst)
cv2.waitKey()
cv2.destroyAllWindows()
Exercise 3:
one image to color space conversion GRAY, while the binarized image, displaying two images, press s save.
Comment out your answer