a.Filters
Image processing is mainly articulated around filters that we can apply on images. This part will quickly introduce you to the more interesting filters and how to use them.
The example below show the usage of various filters and the result showed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Additional informations:
- For smooth function there is various others algorithm like CV_BLUR, CV_GAUSSIAN and many others. We can see that on the smoothed image of lena her face is more plain.
- EqualizedHist intent to equilibrate every possible gray values(0..255) to get a repartition spectrum as flat as possible.
- Threshold is for far the more important filter of all ! It works only on gray picture which pixels values are included between 0 and 255. Then it takes a treshold value all pixels under are set to 0 so black and all the pixels above are set to 255 so white. Note: that CV_THRESH_BINARY_INV just switch to resulting color.
- The second threshold example use CV_THRESH_OTSU which try to equilibrate the balance of black and white to get the same amount on each side.
- The last Dilate replace a pixel value with the maximum value of his neighbors. In this example it also use a specific shape to apply to algorithm that’s why it creates in results large squares.
Original Image:
Smoothed:
Gray:
Equalized:
Thresholded Binary:
Thresholded OTSU:
Dilated:
b. HighGUI
OpenCV comes with a built-in trivial GUI tools that allow the user to show a picture in a window without being obliged to use another gui platform. But it brings a lot more functionalities which include grabbing keyboard events, grabbing mouse position on a window, showing a trackbar. The example below show how to use a trackbar to modify the value of a threshold.
Note: In the sources provided, is also include in example using webcam.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
c. ROI: Region Of Interest
ROI is a pretty interesting feature that allows to select a part of a picture make some operations on it as if it was the entire picture but changes will be applied only to the selected area. Then you can reset the ROI and later changes will be applied on the whole picture. The example below reset to zero a part of an image using ROI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
d. Arithmetics
As we do with numbers we can do arithmetics with picture, but in this case the operation is applied on every pixels. The example below show the effect of different operations on two image of the same size.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Original images:
Add:
AbsDiff:
Mul:
Div:
And:
Or:
Not:
Xor:
Pow:
Max:
<<Starting with OpenCV | Home | Pixel Access and Matrix Iteration>>