void BlendScreen(cv::Mat3b& target_image, const cv::Mat1b& binary_image, cv::Vec3b color) { assert(target_image.size() == binary_image.size()); cv::Size loop_size = target_image.size(); if(target_image.isContinuous() && binary_image.isContinuous()) { loop_size.width *= loop_size.height; loop_size.height = 1; } for(int i = 0; i < loop_size.height; ++i) { cv::Vec3b* target = target_image.ptr<cv::Vec3b>(i); const unsigned char* binary = binary_image.ptr<unsigned char>(i); for(int j = 0; j < loop_size.width; ++j) { if(!binary[j]) { target[j][0] = target[j][0] + color[0] - (target[j][0] * color[0]) / 255; target[j][1] = target[j][1] + color[1] - (target[j][1] * color[1]) / 255; target[j][2] = target[j][2] + color[2] - (target[j][2] * color[2]) / 255; } } } }
void DisjointSets2::process_image(cv::Mat1b & img) { maggieDebug3("process_image()"); if (img.isContinuous() == false) maggieError("process_image() only works with continuous images"); // resizem but with no initial filling resize(img.cols * img.rows); #ifdef TIMER_ON timer.reset(); #endif // TIMER_ON // make the disjoint sets loop nb_comp = 0; //bool is_left_non_null, is_up_non_null; CompIndex idx_current = 0, idx_left = -1, idx_up = -img.cols; CompIndex* roots_ptr = roots; for (CompIndex row = 0; row < img.rows; ++row) { // get the address of row uchar* data = img.ptr<uchar>(row); for (CompIndex col = 0; col < img.cols; ++col) { if (*data++ != 0) { // pixel non black // init roots //*roots_ptr = img.cols * y + x; *roots_ptr = idx_current; ++nb_comp; // check neighbours // bool is_left_non_null = (x > 0 && roots[idx_left] != NO_NODE); // bool is_up_non_null = (y > 0 && roots[idx_up] != NO_NODE); if (col > 0 && roots[idx_left] != NO_NODE) { // left non null if (row > 0 && roots[idx_up] != NO_NODE) { // up non-null maggieDebug3("%i: case 1", idx_current); //idx_current_father = Union(FindSet(idx_left), //idx_current_father Union(FindSet(idx_up), idx_current)); } // end up non-null else { // up null maggieDebug3("%i: case 2", idx_current); //idx_current_father = Union(FindSet(idx_left), idx_current); } // end up null } else { // left null if (row > 0 && roots[idx_up] != NO_NODE) { // up non-null maggieDebug3("%i: case 3", idx_current); //idx_current_father = Union(FindSet(idx_up), idx_current); } // end up non-null else { // up null maggieDebug3("%i: case 4", idx_current); //idx_current_father = idx_current; } // end up null } // end left null //display(img.cols); } // end pixel non black else { // pixel black *roots_ptr = NO_NODE; } // end pixel non black //++img_it; ++idx_left; ++idx_up; ++idx_current; ++roots_ptr; } // end loop col } // end loop row #ifdef TIMER_ON timer.printTime("process_image()"); #endif // TIMER_ON //display(img.cols); }