久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MATLAB vs C++ vs OpenCV - imresize

MATLAB vs C++ vs OpenCV - imresize(MATLAB vs C++ vs OpenCV - imresize)
本文介紹了MATLAB vs C++ vs OpenCV - imresize的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下 MATLAB 代碼,我想將其傳輸到 C++

I have the following MATLAB code which I want to transport into C++

假設 Gr 是二維矩陣并且 1/newscale == 0.5

Assume Gr is 2d matrix and 1/newscale == 0.5

Gr = imresize(Gr, 1 / newScale);

在 MATLAB 文檔中:

B = imresize(A, scale) 返回圖像 B 的縮放倍數A. 輸入圖像 A 可以是灰度、RGB 或二值圖像.如果scale 在 0 到 1.0 之間,B 小于 A.如果 scale 更大小于 1.0,B 大于 A.

B = imresize(A, scale) returns image B that is scale times the size of A. The input image A can be a grayscale, RGB, or binary image. If scale is between 0 and 1.0, B is smaller than A. If scale is greater than 1.0, B is larger than A.

所以這意味著我將得到一個二維矩陣 == matrix_width/2 和 matrix_height/2
我如何計算這些值?根據文檔的默認值來自最近 4X4 的三次插值.

So this means I will get a 2D matrix == matrix_width/2 and matrix_height/2
How do I calculate the values? The default according to the docs are coming from cubic interpolation for nearest 4X4.

我找不到執行相同操作的 C++ 示例代碼.能否提供此類代碼的鏈接?

I can't find a sample code for C++ that does the same. Can you please provide a link to such code?

我還發現 這個 OpenCV 函數,resize.

它和 MATLAB 的功能一樣嗎?

Does it do the same as the MATLAB one?

推薦答案

是的,請注意 MATLAB 的 imresize 有 默認啟用抗鋸齒:

Yes, just be aware that MATLAB's imresize has anti-aliasing enabled by default:

imresize(A,scale,'bilinear')

對比你會用 cv::resize() 得到什么,它沒有抗鋸齒:

vs. what you would get with cv::resize(), which does not have anti-aliasing:

imresize(A,scale,'bilinear','AntiAliasing',false)

正如 Amro 提到的,MATLAB 中的默認值是 bicubic,所以一定要指定.

And as Amro mentioned, the default in MATLAB is bicubic, so be sure to specify.

無需修改代碼即可通過雙線性插值獲得匹配結果.

No code modifications are necessary to get matching results with bilinear interpolation.

示例 OpenCV 代碼段:

Example OpenCV snippet:

cv::Mat src(4, 4, CV_32F);
for (int i = 0; i < 16; ++i)
    src.at<float>(i) = i;

std::cout << src << std::endl;

cv::Mat dst;
cv::resize(src, dst, Size(0, 0), 0.5, 0.5, INTER_LINEAR);

std::cout << dst << std::endl;

輸出 (OpenCV)

[0, 1, 2, 3;
  4, 5, 6, 7;
  8, 9, 10, 11;
  12, 13, 14, 15]

[2.5, 4.5;
  10.5, 12.5]

MATLAB

>> M = reshape(0:15,4,4).';
>> imresize(M,0.5,'bilinear','AntiAliasing',true)
ans =
                     3.125                     4.875
                    10.125                    11.875
>> imresize(M,0.5,'bilinear','AntiAliasing',false)
ans =
                       2.5                       4.5
                      10.5                      12.5

請注意,關閉抗鋸齒后的結果是一樣的.

Note that the results are the same with anti-aliasing turned off.

然而,在'bicubic'INTER_CUBIC 之間,由于權重方案的原因,結果是不同的!參見此處,了解數學差異的詳細信息.問題出在計算三次插值系數的 interpolateCubic() 函數中,其中使用常數 a = -0.75 而不是 a = -0.5 就像在 MATLAB 中一樣.但是,如果您編輯 imgwarp.cpp 并更改代碼:

However, between 'bicubic' and INTER_CUBIC, the results are different on account of the weighting scheme! See here for details on the mathematical difference. The issue is in the interpolateCubic() function that computes the cubic interpolant's coefficients, where a constant of a = -0.75 is used rather than a = -0.5 like in MATLAB. However, if you edit imgwarp.cpp and change the code :

static inline void interpolateCubic( float x, float* coeffs )
{
    const float A = -0.75f;
    ...

到:

static inline void interpolateCubic( float x, float* coeffs )
{
    const float A = -0.50f;
    ...

并重建 OpenCV(提示:禁用 CUDA 和 gpu 模塊以縮短編譯時間),然后您會得到相同的結果:

and rebuild OpenCV (tip: disable CUDA and the gpu module for short compile time), then you get the same results:

MATLAB

>> imresize(M,0.5,'bicubic','AntiAliasing',false)
ans =
                    2.1875                    4.3125
                   10.6875                   12.8125

OpenCV

[0, 1, 2, 3;
  4, 5, 6, 7;
  8, 9, 10, 11;
  12, 13, 14, 15]
[2.1875, 4.3125;
  10.6875, 12.8125]

更多關于立方這里.

這篇關于MATLAB vs C++ vs OpenCV - imresize的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 精品欧美一区二区精品久久久 | 国产一区二区三区四区 | 精品久久久999 | 欧美一区2区三区4区公司 | 午夜影视 | 国产精品欧美一区二区三区 | 国产亚洲第一页 | 天堂网中文字幕在线观看 | 亚洲高清一区二区三区 | 欧美另类视频在线 | 久久一二区 | 国产91精品在线 | 91精品国产色综合久久不卡蜜臀 | 欧美一区二区三区在线观看视频 | 黄色a级一级片 | www,黄色,com | 欧美精品在线一区 | 伊人伊人伊人 | 请别相信他免费喜剧电影在线观看 | 国产一区二区久久 | 欧美中文| 日日夜夜天天 | 亚洲一区二区免费视频 | 精品国产精品 | aaaaa毛片| 中文字幕第一页在线 | 日日淫| 亚洲网站在线 | 青青久久久| 久久6| 亚州成人| 精品一区二区三区在线观看国产 | 欧美综合一区二区三区 | 亚洲国产精品一区二区三区 | 中文字幕在线一区二区三区 | 夜夜爽99久久国产综合精品女不卡 | 超碰在线影院 | 亚洲一区二区电影在线观看 | 久久三区 | 久久久久久久国产精品 | 成人天堂 |