Skip to main content

Posts

Showing posts with the label binary

OpenCV : Image synthesis (ROI, Mask, Binary)

Today we will make Image synthesis by using ROI, Masking, binarization. The full code is like that. #include <iostream> #include "opencv2/opencv.hpp" using namespace std ; using namespace cv ; int main () { Mat me = imread( "./res/pic/mh.jpg" ); Mat animal = imread( "./res/pic/animal_head.png" ); Mat animalGray ; Mat mask_ani ; Mat mask_ani_inv ; imshow( "me origin" , me ); imshow( "animal" , animal ); cvtColor( animal , animalGray , CV_BGR2GRAY); // color to black and white threshold( animalGray , mask_ani , 10 , 255 , 0 ); // make binary bitwise_not( mask_ani , mask_ani_inv ); imshow( "mask ani inv" , mask_ani_inv ); imshow( "mask ani" , mask_ani ); Mat imgRoi ; imgRoi = me ( Rect ( 50 , 50 , animal . cols , animal . rows ) ) ; imshow( "imgRoi" , imgRoi ); Mat me_back ; Mat ani_for ; bitwise_and( animal ...

OpenCV : Threshold (Binary Image)

1. What is binary Image? It is an image made up of two colors, black and white. It is useful to tracking shape or recognizing object. result binary images 2. How to make Binary Image? It can be made by using Threshold method and d epending on the type of flag, you can use various binarizations. double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type); Type : - THRESH_BINARY : if (src(x,y) > thresh) maxval else 0 - THRESH_BINARY_INV : if (src(x,y) > thresh) 0 else maxval - THRESH_TRUNC : if (src(x,y) > thresh) threshold else src(x,y) - THRESH_TOZERO : if (src(x,y) > thresh) src(x,y) else 0 - THRESH_TOZERO_INV : if (src(x,y) > thresh) 0 else src(x,y) Mat img = imread( "./res/text2.jpeg" ); Mat gray , binary , binary2 , binary3 , otsuBinary ; cvtColor( img , gray , CV_RGB2GRAY); // convert to gray color image // if scalar value is bigger then 128, the va...