Ask Your Question

Jishan's profile - activity

2016-10-22 11:54:16 -0600 asked a question Crop Image Patch & Paste

So I am trying to extract a 16x16 patch from the centre of an image and paste it into some random location in the same image and display it. Here is the code I wrote for the same:

void patchPase(Mat& img, Mat& result) {

      Point pt1;
      pt1.x = rng.uniform( x_1, x_2 );
      pt1.y = rng.uniform( y_1, y_2 );
      Mat smallImage;
      smallImage = img(Rect((img.size().width/2),(img.size().height/2), 16, 16));
      Rect roi(Point(pt1.x, pt1.y), smallImage.size());
      smallImage.copyTo(img(roi));
      result = img;
}

However this fails to run with the following error:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp, line 269 terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow

Where have I mistaken? Thanks.

2016-10-22 11:16:12 -0600 commented question Pixel-wise subtraction of image

I get the following error error: conversion from ‘cv::Vec<unsigned char, 3>*’ to non-scalar type ‘cv::Vec3b {aka cv::Vec<unsigned char, 3>}’ requested Vec3b pixel = gray_half.ptr<Vec3b>(i); ^ Any suggestions please?

2016-10-22 10:37:02 -0600 asked a question Pixel-wise subtraction of image

So I am trying to multiply an intensity image with 0.5 and subtract it from each color channel using pixel wise operations like ptr and check that the values do not become negative, i.e. the new (R, G, B) values are (max(R − 0.5I, 0), max(G − 0.5I, 0), max(B − 0.5I, 0)). I am an OpenCV novice, here's the code I came up with (obviously doesn't work). Any pointers will be really helpful:

void pixelwiseSubtraction(Mat& bgrImg, Mat& grayImg, Mat& result) {
  cvtColor(bgrImg, grayImg, CV_BGR2GRAY);
  Mat gray_half;
  cvtColor(grayImg * 0.5, gray_half, CV_GRAY2BGR);

  if(true){
    for (int i = 0; i < gray_half.rows; ++i)
    {
        // point to first color in row
        uchar* pixel = gray_half.ptr<uchar>(i);
        uchar* bgr_pixel = bgrImg.ptr<uchar>(i);
        for (int j = 0; j < gray_half.cols; ++j)
        {
            bgr_pixel -= pixel;
        }
    }
  }

  result = bgrImg;
}

I have an error: invalid conversion from ‘int’ to ‘uchar* {aka unsigned char*}’ [-fpermissive] bgr_pixel -= pixel; error. How can I do the operation?

The not pixel-wise version is this:

void subtractIntensityImage(Mat& bgrImg, Mat& grayImg, Mat& result) {
  cvtColor(bgrImg, grayImg, CV_BGR2GRAY);
  Mat gray_half;
  cvtColor(grayImg * 0.5, gray_half, CV_GRAY2BGR);
  // 2. subtract that from original:
  subtract(bgrImg, gray_half, result);
}

Thanks.

2016-10-22 09:55:11 -0600 commented answer Multiplying Intensity Image Subtraction

Thanks a lot. You have been a great help. my regards.

2016-10-22 09:15:23 -0600 commented answer Multiplying Intensity Image Subtraction

Thanks a lot for clearing my understanding. Is it possible to do it with subtract?

2016-10-22 09:08:59 -0600 received badge  Scholar (source)
2016-10-22 09:08:49 -0600 received badge  Supporter (source)
2016-10-22 08:39:00 -0600 received badge  Editor (source)
2016-10-22 08:38:30 -0600 asked a question Multiplying Intensity Image Subtraction

So I am creating an intensity image as follows:

void convertToGrayImg(Mat& img, Mat& result) {
  Mat gray_img;
  cvtColor(img, gray_img, CV_BGR2GRAY);
  result = gray_img;
}

Now I have to multiply the intensity image I by 0.5 and subtract it from each color channel. How can this be done?

I am confused, do I multiply every pixel with 0.5 or is there a function to do the same? I am very new to OpenCV.

Thanks.