java图像处理之图像融合
生活随笔
收集整理的這篇文章主要介紹了
java图像处理之图像融合
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? 圖像融合,把像素大小相同,拍攝位置相同的照片通過一定方式進行融合。下面介紹幾種簡單的圖像融合方式。
? ? ? ? 1、通過對應像素均值進行融合。這種融合方式可用于處理亮度變換較大的圖片,由于相機測光和成像水平有限,對于成像范圍內陰暗部分和明亮部分往往處理不好,要保證陰暗部分,則會導致明亮部分過曝;要保證明亮部分成像,則會導致陰暗部分太暗。對于這種情況,一種是采用較低的曝光參數保證明亮部分不過曝,通過調整亮度顯示出陰影部分,再通過均值合并生成圖像。第二種方法是通過相機拍攝,相機采用三腳架固定位置,用不同曝光參數進行拍攝,拍攝完成后將幾張影像進行均值合并。
? ? ? ? 另外,某些“鬼影”照片其實也是用類似方式合成的。
? ? ? ? 代碼:
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、通過對應像素值求和。適用于亮度很暗的場景,由于在亮度很低的場景下,采用高ISO可能會產生很多噪點,可以通過較低的曝光參數,固定相機位置,采用多次拍攝,對多張照片進行對應位置像素值求和的方式提高亮度和畫質。
? ? ? ? 另外也可以用于對影像進行特征提取或邊緣提取后,將處理后的特征點、線圖像與原圖進行合并。
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;}?
總結
以上是生活随笔為你收集整理的java图像处理之图像融合的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java图像处理,彩色图像转灰度图的几种
- 下一篇: java图像处理之图像裁剪