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);
}
Need points to upload image :( srcImage : My source image
dstImage : ()
goalImage : Kind of smoothness I want to achieve after transformation.