Opencv for python: simple image changes

Source: Internet
Author: User

Import cv2.cv as cv


# Load image
Filename = "../Video/cat.jpg"
Image = cv. LoadImage (filename)


# Set created image
Size = cv. GetSize (image) # (100,100)
Depth = 8
Channels = 1

Grayscale Processing
Gray = cv. CreateImage (size, depth, channels) # create one 100x100 single channels image
Cv. CvtColor (image, gray, cv. CV_BGR2GRAY)

Smooth de-noise, making the place where the image changes dramatically over-smooth, that is, blurring the line between different colors on the Image

Smooth = cv. CreateImage (size, depth, channels)
Cv. Smooth (gray, smooth, cv. CV_MEDIAN)

Balance operation: Calculate the pixel value of an image, draw a histogram, and then balance (the impression is to make the histogram distribution closer to the normal distribution) www.2cto.com

Equalize = cv. CreateImage (size, depth, channels)
Cv. Smooth (gray, equalize)

Laplace operation: You can highlight the outlines in an image.

Laplace = cv. CreateImage (size, depth, channels) # create one 100x100 single channels image
Cv. CvtColor (image, Laplace, cv. CV_BGR2GRAY)
Dst_16s2 = cv. CreateImage (size, cv. IPL_DEPTH_16S, 1)
Cv. Laplace (Laplace, dst_16s2)
Cv. Convert (dst_16s2, Laplace)

# Create a window
Win_name1 = "gray"
Win_name2 = "smooth"
Win_name3 = "equalize"
Win_name4 = "Laplace"
Cv. NamedWindow (win_name1)
Cv. NamedWindow (win_name2)
Cv. NamedWindow (win_name3)
Cv. NamedWindow (win_name4)
# Cv. NamedWindow (win_name5)
Cv. ShowImage (win_name1, gray)
Cv. ShowImage (win_name2, smooth)
Cv. ShowImage (win_name3, equalize)
Cv. ShowImage (win_name4, Laplace)
Cv. WaitKey ()

Grayscale result



Smooth Noise Removal

 
 

Histogram equalization result

 
 

Laplace operation result

 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.