图像处理之高斯金字塔 (五)

2014-11-24 10:41:14 · 作者: · 浏览: 3
els[index] >> 24) & 0xff;
tr = (reducePixels[index] >> 16) & 0xff;
tg = (reducePixels[index] >> 8) & 0xff;
tb = reducePixels[index] & 0xff;

ta = (expandPixels[index] >> 24) & 0xff;
er = (expandPixels[index] >> 16) & 0xff;
eg = (expandPixels[index] >> 8) & 0xff;
eb = expandPixels[index] & 0xff;

tr = tr - er;
tg = tg - eg;
tb = tb - eb;

laPixels[index] = (ta << 24) | (clamp(tr) << 16) | (clamp(tg) << 8) | clamp(tb);
}
}
setRGB( laplaciImages[i-1], 0, 0, width, height, laPixels );
}

return laplaciImages;
}

private BufferedImage pyramidReduce(BufferedImage src) {
int width = src.getWidth();
int height = src.getHeight();
BufferedImage dest = createSubCompatibleDestImage(src, null);
int[] inPixels = new int[width*height];
int ow = width/2;
int oh = height/2;
int[] outPixels = new int[ow*oh];
getRGB(src, 0, 0, width, height, inPixels );
int inRow=0, inCol = 0, index = 0, oudex =0, ta = 0;
float[][] keneralData = this.getHVGaussianKeneral();
for(int row=0; row for(int col=0; col inRow = 2* row;
inCol = 2* col;
if(inRow >= height) {
inRow = 0;
}
if(inCol >= width) {
inCol = 0;
}
float sumRed = 0, sumGreen = 0, sumBlue = 0;
for(int subRow = -2; subRow <= 2; subRow++) {
int inRowOff = inRow + subRow;
if(inRowOff >= height || inRowOff < 0) {
inRowOff = 0;
}
for(int subCol = -2; subCol <= 2; subCol++) {
int inColOff = inCol + subCol;
if(inColOff >= width || inColOff < 0) {
inColOff = 0;
}
index = inRowOff * width + inColOff;
ta = (inPixels[index] >> 24) & 0xff;
int red = (inPixels[index] >> 16) & 0xff;
int green = (inPixels[index] >> 8) & 0xff;
int blue = inPixels[index] & 0xff;
sumRed += keneralData[subRow + 2][subCol + 2] * red;
sumGreen += keneralData[subRow + 2][subCol + 2] * green;
sumBlue += keneralData[subRow + 2][subCol + 2] * blue;
}
}

oudex = row * ow + col;
outPixels[oudex] = (ta << 24) | (clamp(sumRed) << 16) | (clamp(sumGreen) << 8) | clamp(sumBlue);
}
}
setRGB( dest, 0, 0, ow, oh, outPixels );
return dest;
}

public BufferedImage createSubCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
if ( dstCM == null )
dstCM = src.getColorModel();
return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(src.getWidth()/2, src.getHeight()/2), dstCM.isAlphaPremultiplied(), null);
}

public BufferedImage createTwiceCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
if ( dstCM == nul