Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Access sub-image in opencv

$
0
0
Hi, I am new in opencv, i am using opencv 3.0, i am trying to access a sub-image, ![Original image](/upfiles/14762596703620534.png) As i know there is a 2 ways to do it, using **rect** or **range** **using range to access the top quarter of the image** using namespace cv; int main() { Mat img_l = imread("left2.png",IMREAD_GRAYSCALE); img_l.convertTo(img_l, CV_64FC1); //convert to double in gray scale Mat leftROI = img_l(Range(0, img_l.rows/2), Range(0,img_l.cols/2)); cv::normalize(leftROI, leftROI, 0, 1, cv::NORM_MINMAX); //to view imshow("opencvtest1",leftROI); waitKey(0); return 0; } ![The output is ](/upfiles/1476259612990219.png) **using rect** using namespace cv; int main() { Mat img_l = imread("left2.png",IMREAD_GRAYSCALE); img_l.convertTo(img_l, CV_64FC1); //convert to double in gray scale Mat leftROI = img_l(Rect(0,0, img_l.cols/2 , img_l.rows/2)); cv::normalize(leftROI, leftROI, 0, 1, cv::NORM_MINMAX); //to view imshow("opencvtest1",leftROI); waitKey(0); return 0; } ![The output is](/upfiles/14762596961120677.png) However the output images does not seem right, the sub images are no the top left quarter but when i use **matlab** x = imread('left2.png' ); x = rgb2gray(x); leftROI = x(1:size(x,1)/2,1:size(x,2)/2); imshow(leftROI) ![The output is ](/upfiles/14762597225775825.png) , The output of matlab seems right could anyone help why is opencv not right?

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>