I want to upscale / stretch an image horizontally but each pixel row needs a different scale depending upon the position of the row or row-number ?
I did it by cropping source image row by row int a 1 pixel high crop and then using resize to do scale each row differently as I want, and finally copy the scaled row of pixels on a resultant image: here's my code:
cv::Rect rowCropRect = cv::Rect(0,i, imgOut.size().width, 1);
cv::Size scaledSize = cv::Size((1.f - smallFrameRatio) * rowCropRect.size().width, 1);
if (smallestWidth < scaledSize.width)
smallestWidth = scaledSize.width;
Mat eachRowCrop(imgIn, rowCropRect);
resize(eachRowCrop, eachRowCrop, scaledSize);
rowCropRect.x = (imgIn.size().width - eachRowCrop.size().width) * 0.5f;
rowCropRect.width = eachRowCrop.size().width;
if (rowCropRect.x < 0) rowCropRect.x = 0;
if (rowCropRect.width >= imgOut.size().width) rowCropRect.width = imgOut.size().width - 5;
eachRowCrop.copyTo(imgOut(rowCropRect));
eachRowCrop.release();
I'm doing this by iterating each row in a loop. But its slower and resultant transform is not good enough.
I want to be able to do it directly at pixel level, using some interpolation maths which cv::resize() is internally using, OR some other efficient way.
Any ideas ?
SourceImage:
ResultImage: