欢迎来到天天文库
浏览记录
ID:62067387
大小:441.50 KB
页数:15页
时间:2021-04-16
《图像的高斯金字塔,用java编写的.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、个人收集整理勿做商业用途一:图像金字塔基本操作对一张图像不断的模糊之后向下采样,得到不同分辨率的图像,同时每次得到的新的图像宽与高是原来图像的1/2,最常见就是基于高斯的模糊之后采样,得到的一系列图像称为高斯金字塔。个人收集整理勿做商业用途高斯金字塔不同(DoG)又称为拉普拉斯金字塔,其计算公式如下:个人收集整理勿做商业用途L(i)=G(i)–expand(G(i+1))第i层拉普拉斯金字塔是由第i层高斯金字塔减去第i+1层高斯金字塔expand之后得到。本文得到的DoG(DifferenceofGaussian)结果如下:二:关键代码解析金字塔red
2、uce操作实现代码如下:[java]viewplaincopy1privateBufferedImagepyramidReduce(BufferedImagesrc){2intwidth=src.getWidth();个人收集整理勿做商业用途1intheight=src。getHeight();2BufferedImagedest=createSubCompatibleDestImage(src,null);3int[]inPixels=newint[width*height];4intow=width/2;5intoh=height/2;6int[]
3、outPixels=newint[ow*oh];7getRGB(src,0,0,width,height,inPixels);8intinRow=0,inCol=0,index=0,oudex=0,ta=0;9float[][]keneralData=this.getHVGaussianKeneral();10for(introw=0;row〈oh;row++){11for(intcol=0;col4、nCol〉=width){18inCol=0;19}20floatsumRed=0,sumGreen=0,sumBlue=0;21for(intsubRow=—2;subRow<=2;subRow++){22intinRowOff=inRow+subRow;23if(inRowOff〉=height||inRowOff〈0){24inRowOff=0;25}26for(intsubCol=-2;subCol〈=2;subCol++){27intinColOff=inCol+subCol;28if(inColOff〉=width|5、inColOff<0)6、{29inColOff=0;30}31index=inRowOff*width+inColOff;32ta=(inPixels[index]>>24)&0xff;33intred=(inPixels[index]>>16)&0xff;34intgreen=(inPixels[index]〉>8)&0xff;35intblue=inPixels[index]&0xff;36sumRed+=keneralData[subRow+2][subCol+2]*red;37sumGreen+=keneralData[subRow+2][subCol+2]*gree7、n;38sumBlue+=keneralData[subRow+2][subCol+2]*blue;39}40}4142oudex=row*ow+col;43outPixels[oudex]=(ta〈<24)8、(clamp(sumRed)<<16)9、(clamp(sumGreen)<〈8)10、clamp(sumBlue);个人收集整理勿做商业用途1}2}3setRGB(dest,0,0,ow,oh,outPixels);4returndest;5}金字塔expand实现代码如下:[java]viewplaincopy6publicBufferedImag11、epyramidExpand(BufferedImagesrc){7intwidth=src。getWidth();8intheight=src。getHeight();9int[]inPixels=newint[width*height];10getRGB(src,0,0,width,height,inPixels);11intow=2*width;12intoh=2*height;13int[]outPixels=newint[ow*oh];14intindex=0,outdex=0,ta=0;15float[][]keneralData=this12、。getHVGaussianKeneral();16BufferedImagedest=cre
4、nCol〉=width){18inCol=0;19}20floatsumRed=0,sumGreen=0,sumBlue=0;21for(intsubRow=—2;subRow<=2;subRow++){22intinRowOff=inRow+subRow;23if(inRowOff〉=height||inRowOff〈0){24inRowOff=0;25}26for(intsubCol=-2;subCol〈=2;subCol++){27intinColOff=inCol+subCol;28if(inColOff〉=width|
5、inColOff<0)
6、{29inColOff=0;30}31index=inRowOff*width+inColOff;32ta=(inPixels[index]>>24)&0xff;33intred=(inPixels[index]>>16)&0xff;34intgreen=(inPixels[index]〉>8)&0xff;35intblue=inPixels[index]&0xff;36sumRed+=keneralData[subRow+2][subCol+2]*red;37sumGreen+=keneralData[subRow+2][subCol+2]*gree
7、n;38sumBlue+=keneralData[subRow+2][subCol+2]*blue;39}40}4142oudex=row*ow+col;43outPixels[oudex]=(ta〈<24)
8、(clamp(sumRed)<<16)
9、(clamp(sumGreen)<〈8)
10、clamp(sumBlue);个人收集整理勿做商业用途1}2}3setRGB(dest,0,0,ow,oh,outPixels);4returndest;5}金字塔expand实现代码如下:[java]viewplaincopy6publicBufferedImag
11、epyramidExpand(BufferedImagesrc){7intwidth=src。getWidth();8intheight=src。getHeight();9int[]inPixels=newint[width*height];10getRGB(src,0,0,width,height,inPixels);11intow=2*width;12intoh=2*height;13int[]outPixels=newint[ow*oh];14intindex=0,outdex=0,ta=0;15float[][]keneralData=this
12、。getHVGaussianKeneral();16BufferedImagedest=cre
此文档下载收益归作者所有