Ask Your Question

dhaval's profile - activity

2017-04-16 23:49:11 -0600 received badge  Supporter (source)
2017-04-16 23:32:55 -0600 commented answer How to get smooth image after transforming by changing pixel position using opencv?

@berak : thanks for your expert input. this is what I was looking for.

2017-04-16 23:31:51 -0600 received badge  Scholar (source)
2017-04-14 11:32:03 -0600 commented question How to get smooth image after transforming by changing pixel position using opencv?

@kbarni : yup, it seems I need to go title bit more close to the problem and small image will help to debug.. thanks.

2017-04-14 09:15:38 -0600 commented question How to get smooth image after transforming by changing pixel position using opencv?

@StevenPuttemans : Thanks !

2017-04-14 09:15:06 -0600 received badge  Editor (source)
2017-04-14 05:28:58 -0600 asked a question How to get smooth image after transforming by changing pixel position using opencv?

I am transforming image using opencv in following way. but, I am getting distorted image. any way to get the smoothly transformed image(as per the attached last - goalImage) ?

I have tried using warpPerspective, warpAffine. it is producing smooth transformation but, transformation that is needed is not been possible to get based on calculating just 4 points.

I have used blur, GaussianBlur, medianBlur, bilateralFilter on dstImage but, still not getting favorable result.

Mat_<Vec3b> srcImage = imread("C:/images/0.jpg", CV_LOAD_IMAGE_COLOR);
Mat_<Vec3b> dstImage = srcImage.clone();
for (int i = 0; i < dstImage.rows; i++)
    {
        for (int j = 0; j < dstImage.cols; j++)
        {
            //calculating rnew and thetanew -- from i and j
            ynew = rnew * sin(thetanew);

            dstImage(i, j)[0] = srcImage(i, ynew)[0];
            dstImage(i, j)[1] = srcImage(i, ynew)[1];
            dstImage(i, j)[2] = srcImage(i, ynew)[2];

            //I have tried following way also, but result is same
            //dstImage(i, j) = getColorSubpix(eiffel, cv::Point2f(i, ynew));

        }
    }

cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt)
{
    assert(!img.empty());
    assert(img.channels() == 3);

    int x = (int)pt.x;
    int y = (int)pt.y;

    int x0 = cv::borderInterpolate(x,   img.cols, cv::BORDER_REFLECT_101);
    int x1 = cv::borderInterpolate(x+1, img.cols, cv::BORDER_REFLECT_101);
    int y0 = cv::borderInterpolate(y,   img.rows, cv::BORDER_REFLECT_101);
    int y1 = cv::borderInterpolate(y+1, img.rows, cv::BORDER_REFLECT_101);

    float a = pt.x - (float)x;
    float c = pt.y - (float)y;

    uchar b = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[0] * a) * (1.f - c)
                           + (img.at<cv::Vec3b>(y1, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[0] * a) * c);
    uchar g = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[1] * a) * (1.f - c)
                           + (img.at<cv::Vec3b>(y1, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[1] * a) * c);
    uchar r = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[2] * a) * (1.f - c)
                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);

    return cv::Vec3b(b, g, r);
}

srcImage : My source image

dstImage :My output image

Instead of broken lines in above image, I want to produce smooth lines like below image

goalImage : Kind of smoothness I want to achieve after transformation