我正在尝试使用最近邻插值算法编写自己的函数来放大输入图像.不好的部分是我能够看到它是如何工作但无法找到算法本身.我将不胜感激任何帮助.
这是我尝试将输入图像放大2倍的原因:
function output = nearest(input)
[x,y]=size(input);
output = repmat(uint8(0),x*2,y*2);
[newwidth,newheight]=size(output);
for i=1:y
for j=1:x
xloc = round ((j * (newwidth+1)) / (x+1));
yloc = round ((i * (newheight+1)) / (y+1));
output(xloc,yloc) = input(j,i);
end
end
Run Code Online (Sandbox Code Playgroud)
这是马克建议之后的输出
matlab interpolation image-processing nearest-neighbor resize-image
描述:- 我试图在不使用 C++ 中的 OpenCV 函数的情况下旋转图像。旋转中心不必是图像的中心。它可能是一个不同的点(从图像中心偏移)。到目前为止,我遵循了各种来源来进行图像插值,并且我知道有一个来源可以在 MATLAB 中完美地完成这项工作。我试图在没有 OpenCV 函数的 C++ 中模仿相同的内容。但我没有得到预期的旋转图像。相反,我的输出在屏幕上看起来像一条小的水平线。
void RotateNearestNeighbor(cv::Mat src, double angle) {
int oldHeight = src.rows;
int oldWidth = src.cols;
int newHeight = std::sqrt(2) * oldHeight;
int newWidth = std::sqrt(2) * oldWidth;
cv::Mat output = cv::Mat(newHeight, newWidth, src.type());
double ctheta = cos(angle);
double stheta = sin(angle);
for (size_t i = 0; i < newHeight; i++) {
for (size_t j = 0; j < newWidth; j++) {
int oldRow = static_cast<int> ((i - …Run Code Online (Sandbox Code Playgroud) 我正在使用GD库来动态创建图像.
但是当我使用imagerotate()函数旋转图像时,
它可以正常工作,但它会产生非常刺激的图像
旋转粗糙边缘.
如图所示.
那么如何使旋转图像的这些边/边平滑?