java图像处理之图像融合
? ? ? ? 圖像融合,把像素大小相同,拍攝位置相同的照片通過一定方式進(jìn)行融合。下面介紹幾種簡(jiǎn)單的圖像融合方式。
? ? ? ? 1、通過對(duì)應(yīng)像素均值進(jìn)行融合。這種融合方式可用于處理亮度變換較大的圖片,由于相機(jī)測(cè)光和成像水平有限,對(duì)于成像范圍內(nèi)陰暗部分和明亮部分往往處理不好,要保證陰暗部分,則會(huì)導(dǎo)致明亮部分過曝;要保證明亮部分成像,則會(huì)導(dǎo)致陰暗部分太暗。對(duì)于這種情況,一種是采用較低的曝光參數(shù)保證明亮部分不過曝,通過調(diào)整亮度顯示出陰影部分,再通過均值合并生成圖像。第二種方法是通過相機(jī)拍攝,相機(jī)采用三腳架固定位置,用不同曝光參數(shù)進(jìn)行拍攝,拍攝完成后將幾張影像進(jìn)行均值合并。
? ? ? ? 另外,某些“鬼影”照片其實(shí)也是用類似方式合成的。
? ? ? ? 代碼:
public BufferedImage imageCombineByAverage(List<BufferedImage> images) { BufferedImage tempImage = new BufferedImage(images.get(0).getWidth(), images.get(0).getHeight(), images.get(0).getType());for(int i = 0; i < images.get(0).getWidth(); i++) {for(int j = 0; j < images.get(0).getHeight(); j++) {int R = 0,G = 0,B = 0;for(BufferedImage image : images) {int rgb = image.getRGB(i, j);int r = (rgb >> 16) & 0xff;int g = (rgb >> 8) & 0xff;int b = rgb & 0xff;R += r;G += g;B += b;}int aveR = R / images.size();int aveG = G / images.size();int aveB = B / images.size();int RGB = (255 & 0xff) << 24 | (clamp(aveR) & 0xff) << 16 | (clamp(aveG) & 0xff) << 8 | clamp(aveB) & 0xff;tempImage.setRGB(i, j, RGB);}} return tempImage;}? ? ? ? 2、通過對(duì)應(yīng)像素值求和。適用于亮度很暗的場(chǎng)景,由于在亮度很低的場(chǎng)景下,采用高ISO可能會(huì)產(chǎn)生很多噪點(diǎn),可以通過較低的曝光參數(shù),固定相機(jī)位置,采用多次拍攝,對(duì)多張照片進(jìn)行對(duì)應(yīng)位置像素值求和的方式提高亮度和畫質(zhì)。
? ? ? ? 另外也可以用于對(duì)影像進(jìn)行特征提取或邊緣提取后,將處理后的特征點(diǎn)、線圖像與原圖進(jìn)行合并。
public BufferedImage imageCombineByAddAll(List<BufferedImage> images) { BufferedImage tempImage = new BufferedImage(images.get(0).getWidth(), images.get(0).getHeight(), images.get(0).getType());for(int i = 0; i < images.get(0).getWidth(); i++) {for(int j = 0; j < images.get(0).getHeight(); j++) {int R = 0,G = 0,B = 0;for(BufferedImage image : images) {int rgb = image.getRGB(i, j);int r = (rgb >> 16) & 0xff;int g = (rgb >> 8) & 0xff;int b = rgb & 0xff;R += r;G += g;B += b;}int RGB = (255 & 0xff) << 24 | (clamp(R) & 0xff) << 16 | (clamp(G) & 0xff) << 8 | clamp(B) & 0xff;tempImage.setRGB(i, j, RGB);}} return tempImage;}? ? ? ? 3、最低值合并。
public BufferedImage imageCombineByMin(List<BufferedImage> images) { BufferedImage tempImage = new BufferedImage(images.get(0).getWidth(), images.get(0).getHeight(), images.get(0).getType());for(int i = 0; i < images.get(0).getWidth(); i++) {for(int j = 0; j < images.get(0).getHeight(); j++) {List<Integer> rList = new ArrayList<>();List<Integer> gList = new ArrayList<>();List<Integer> bList = new ArrayList<>();for(BufferedImage image : images) {int rgb = image.getRGB(i, j);int r = (rgb >> 16) & 0xff;int g = (rgb >> 8) & 0xff;int b = rgb & 0xff;rList.add(r);gList.add(g);bList.add(b);}Collections.sort(rList);Collections.sort(gList);Collections.sort(bList);int minR = rList.get(0);int minG = gList.get(0);int minB = bList.get(0);int RGB = (255 & 0xff) << 24 | (clamp(minR) & 0xff) << 16 | (clamp(minG) & 0xff) << 8 | clamp(minB) & 0xff;tempImage.setRGB(i, j, RGB);}} return tempImage;}?
總結(jié)
以上是生活随笔為你收集整理的java图像处理之图像融合的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java图像处理,彩色图像转灰度图的几种
- 下一篇: java图像处理之图像裁剪