Preface
In a previous article, we explained the edge gradient computing function, which we'll look at in the image pyramid.
image pyramid?
Image pyramid is widely used in computer vision applications.
Image Pyramid is an image set, all the images in the set originate from the same original image, and are obtained by successive descending sampling of the original image.
The common image pyramid has the following two kinds:
• Gauss Pyramid (Gaussian pyramid): Used to sample down
• Laplace pyramid (Laplacian Pyramid): Used to reconstruct the upper layer of the image from the lower pyramid
Gauss Pyramid
Like the pyramid, the Gaussian pyramid is gradually sampled from the underlying original graph, getting smaller and lower.
So how do you get the next layer of images?
First, and the Gaussian kernel convolution:
Then, delete all the even rows.
Visible, this next level of image is about 1/4 of the previous level.
So how does the upward transformation change?
First, expand the row of pictures to twice times the original, and then add the rows and columns with a 0 fill.
Finally, multiply the volume by 4 after the Gaussian kernel.
The realization of Gauss pyramid
Copy Code code as follows:
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
This is a & 1 equivalent to a% 2, which is divided by the remainder of 2.
When we do not follow the above steps, because the child efficiency is low, but directly to create a matrix of the original matrix 1/4, and then the convolution of the time to skip those rows and columns to be deleted.
Also below, after the creation of convolution, because some places must be 0, so the actual convolution process, the kernel some elements are ignored.
Copy Code code as follows:
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;
};
Effect chart