最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jsvascript圖像處理—(計(jì)算機(jī)視覺(jué)應(yīng)用)圖像金字塔

 更新時(shí)間:2013年01月15日 14:11:09   作者:  
上一篇文章,我們講解了邊緣梯度計(jì)算函數(shù),這篇文章我們來(lái)了解圖像金字塔;圖像金字塔被廣泛用于計(jì)算機(jī)視覺(jué)應(yīng)用中;圖像金字塔是一個(gè)圖像集合,集合中所有的圖像都源于同一個(gè)原始圖像,而且是通過(guò)對(duì)原始圖像連續(xù)降采樣獲得的
前言
上一篇文章,我們講解了邊緣梯度計(jì)算函數(shù),這篇文章我們來(lái)了解圖像金字塔。

圖像金字塔?
圖像金字塔被廣泛用于計(jì)算機(jī)視覺(jué)應(yīng)用中。
圖像金字塔是一個(gè)圖像集合,集合中所有的圖像都源于同一個(gè)原始圖像,而且是通過(guò)對(duì)原始圖像連續(xù)降采樣獲得的。

常見(jiàn)的圖像金字塔有下面兩種
•高斯金字塔(Gaussian pyramid): 用來(lái)向下采樣
•拉普拉斯金字塔(Laplacian pyramid): 用來(lái)從金字塔低層圖像重建上層未采樣圖像

高斯金字塔

Pyramid figure


類似金字塔一樣,高斯金字塔從底層原始圖逐漸向下采樣,越來(lái)越小。

那么如何獲取下一層圖像呢?

首先,和高斯內(nèi)核卷積:
\frac{1}{16} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix} 
然后,將所有偶數(shù)行列刪掉。
可見(jiàn),這樣下一級(jí)圖像約為上一級(jí)的1/4。

那么向上變換如何變換呢?
首先先將圖片行列擴(kuò)大為原來(lái)的兩倍,然后將添加的行列用0填充。
最后用剛剛的高斯內(nèi)核乘以4后卷積。

高斯金字塔實(shí)現(xiàn)
復(fù)制代碼 代碼如下:

var pyrDown = function(__src, __dst){
__src || error(arguments.callee, IS_UNDEFINED_OR_NULL/* {line} */);
if(__src.type && __src.type == "CV_RGBA"){
var width = __src.col,
height = __src.row,
dWidth = ((width & 1) + width) / 2,
dHeight = ((height & 1) + height) / 2,
sData = __src.data,
dst = __dst || new Mat(dHeight, dWidth, CV_RGBA),
dstData = dst.data;
var withBorderMat = copyMakeBorder(__src, 2, 2, 0, 0),
mData = withBorderMat.data,
mWidth = withBorderMat.col;
var newValue, nowX, offsetY, offsetI, dOffsetI, i, j;
var kernel = [1, 4, 6, 4, 1,
, 16, 24, 16, 4,
, 24, 36, 24, 6,
, 16, 24, 16, 4,
, 4, 6, 4, 1
];
for(i = dHeight; i--;){
dOffsetI = i * dWidth;
for(j = dWidth; j--;){
for(c = 3; c--;){
newValue = 0;
for(y = 5; y--;){
offsetY = (y + i * 2) * mWidth * 4;
for(x = 5; x--;){
nowX = (x + j * 2) * 4 + c;
newValue += (mData[offsetY + nowX] * kernel[y * 5 + x]);
}
}
dstData[(j + dOffsetI) * 4 + c] = newValue / 256;
}
dstData[(j + dOffsetI) * 4 + 3] = mData[offsetY + 2 * mWidth * 4 + (j * 2 + 2) * 4 + 3];
}
}
}else{
error(arguments.callee, UNSPPORT_DATA_TYPE/* {line} */);
}
return dst;
};

dWidth = ((width & 1) + width) / 2,
dHeight = ((height & 1) + height) / 2
這里面a & 1等同于a % 2,即求除以2的余數(shù)。
我們實(shí)現(xiàn)時(shí)候沒(méi)有按照上面的步驟,因?yàn)檫@樣子效率就低了,而是直接創(chuàng)建一個(gè)原矩陣1/4的矩陣,然后卷積時(shí)候跳過(guò)那些要被刪掉的行和列。

下面也一樣,創(chuàng)建后卷積,由于一些地方一定是0,所以實(shí)際卷積過(guò)程中,內(nèi)核有些元素是被忽略的。
復(fù)制代碼 代碼如下:

var pyrUp = function(__src, __dst){
__src || error(arguments.callee, IS_UNDEFINED_OR_NULL/* {line} */);
if(__src.type && __src.type == "CV_RGBA"){
var width = __src.col,
height = __src.row,
dWidth = width * 2,
dHeight = height * 2,
sData = __src.data,
dst = __dst || new Mat(dHeight, dWidth, CV_RGBA),
dstData = dst.data;
var withBorderMat = copyMakeBorder(__src, 2, 2, 0, 0),
mData = withBorderMat.data,
mWidth = withBorderMat.col;
var newValue, nowX, offsetY, offsetI, dOffsetI, i, j;
var kernel = [1, 4, 6, 4, 1,
, 16, 24, 16, 4,
, 24, 36, 24, 6,
, 16, 24, 16, 4,
, 4, 6, 4, 1
];
for(i = dHeight; i--;){
dOffsetI = i * dWidth;
for(j = dWidth; j--;){
for(c = 3; c--;){
newValue = 0;
for(y = 2 + (i & 1); y--;){
offsetY = (y + ((i + 1) >> 1)) * mWidth * 4;
for(x = 2 + (j & 1); x--;){
nowX = (x + ((j + 1) >> 1)) * 4 + c;
newValue += (mData[offsetY + nowX] * kernel[(y * 2 + (i & 1 ^ 1)) * 5 + (x * 2 + (j & 1 ^ 1))]);
}
}
dstData[(j + dOffsetI) * 4 + c] = newValue / 64;
}
dstData[(j + dOffsetI) * 4 + 3] = mData[offsetY + 2 * mWidth * 4 + (((j + 1) >> 1) + 2) * 4 + 3];
}
}
}else{
error(arguments.callee, UNSPPORT_DATA_TYPE/* {line} */);
}
return dst;
};

效果圖

相關(guān)文章

最新評(píng)論

山西省| 舒城县| 蓬安县| 石家庄市| 中江县| 尼木县| 仪陇县| 鄢陵县| 安图县| 崇明县| 仁布县| 诸城市| 富川| 治县。| 平阳县| 泾川县| 东宁县| 浪卡子县| 肥东县| 曲松县| 和林格尔县| 新疆| 甘洛县| 体育| 扎鲁特旗| 乐山市| 萨嘎县| 扎囊县| 凤庆县| 剑河县| 即墨市| 芦山县| 汝城县| 福鼎市| 密云县| 施秉县| 武鸣县| 霞浦县| 高阳县| 长宁县| 根河市|