Draw the look-up tables that would display the following: (i) a band of pixels,
ID: 3883509 • Letter: D
Question
Draw the look-up tables that would display the following: (i) a band of pixels, between Thr1 and Thr2, as white (foreground) and all other pixels as black (background); (ii) a band of pixels, between Thr1 and Thr2, as their “normal” (default) shades of gray, and all other pixels as black (background).
Explanation / Answer
// idea: keep all the pixels from front image that are inside your 6 points area always unblended: cv::Mat blendFrontAlpha(cv::Mat front, cv::Mat left, cv::Mat right, std::vector sixPoints, cv::Mat frontForeground = cv::Mat()) { // define some maximum distance. No information of the front image is used if it's further away than that maxDist. // if you have some real masks, you can easily set the maxDist according to the dimension of that mask - dimension of the 6-point-mask float maxDist = 10; // to use the cv function to draw contours we must order it like this: std::vector contours; contours.push_back(sixPoints); // create the mask cv::Mat frontMask = cv::Mat::zeros(front.rows, front.cols, CV_8UC1); // draw those 6 points connected as a filled contour cv::drawContours(frontMask,contours,0,cv::Scalar(255),-1); // add "lines": everything left from the points 3-4-5 might be used from left image, everything from the points 0-1-2 might be used from the right image: cv::Mat leftMask = cv::Mat::zeros(front.rows, front.cols, CV_8UC1); { cv::Point2f center = cv::Point2f(sixPoints[3].x, sixPoints[3].y); float steigung = ((float)sixPoints[5].y - (float)sixPoints[3].y)/((float)sixPoints[5].x - (float)sixPoints[3].x); if(sixPoints[5].x - sixPoints[3].x == 0) steigung = 2*front.rows; float n = center.y - steigung*center.x; cv::Point2f top = cv::Point2f( (0-n)/steigung , 0); cv::Point2f bottom = cv::Point2f( (front.rows-1-n)/steigung , front.rows-1); // now create the contour of the left image: std::vector leftMaskContour; leftMaskContour.push_back(top); leftMaskContour.push_back(bottom); leftMaskContour.push_back(cv::Point(0,front.rows-1)); leftMaskContour.push_back(cv::Point(0,0)); std::vector leftMaskContours; leftMaskContours.push_back(leftMaskContour); cv::drawContours(leftMask,leftMaskContours,0,cv::Scalar(255),-1); cv::imshow("leftMask", leftMask); cv::imwrite("x_leftMask.png", leftMask); } // add "lines": everything left from the points 3-4-5 might be used from left image, everything from the points 0-1-2 might be used from the right image: cv::Mat rightMask = cv::Mat::zeros(front.rows, front.cols, CV_8UC1); { // add "lines": everything left from the points 3-4-5 might be used from left image, everything from the points 0-1-2 might be used from the right image: cv::Point2f center = cv::Point2f(sixPoints[2].x, sixPoints[2].y); float steigung = ((float)sixPoints[0].y - (float)sixPoints[2].y)/((float)sixPoints[0].x - (float)sixPoints[2].x); if(sixPoints[0].x - sixPoints[2].x == 0) steigung = 2*front.rows; float n = center.y - steigung*center.x; cv::Point2f top = cv::Point2f( (0-n)/steigung , 0); cv::Point2f bottom = cv::Point2f( (front.rows-1-n)/steigung , front.rows-1); std::coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.