我有兩張照片,一張是放大的,第二張是大的廣角照片??紤]第一個(gè)圖像是第二個(gè)圖像的裁剪(盡管它不是)。我從每張照片中選擇一個(gè)像素,代表兩張照片中的相同事物(比如一個(gè)男人的鼻子)。我將第一張圖片以一定的透明度覆蓋在第二張圖片的頂部,對(duì)齊兩個(gè)選定的像素?現(xiàn)在我想縮放第二張圖像,直到第一張圖像基本上消失,因?yàn)榈诙垐D像的比例與第一張圖像的比例匹配。我正在使用 OpenImaj,并使用 MBFImage.overlayInPlace() 成功完成了這項(xiàng)工作。我遇到的問(wèn)題是,當(dāng)我使用 ResizeProcessor 縮放第二個(gè)圖像時(shí),如果我必須將第二個(gè)圖像縮放太多( >5x ),我會(huì)得到一個(gè)“OutOfMemoryError: Java Heap Space”。我已經(jīng)使用 JDK 12 64bit 將 -Xmx 提升到 12G。我嘗試了 ResizeProcessor、BilinearInterpolation 和 BicubicInterpolation 調(diào)整器,結(jié)果都一樣。這是我最近嘗試的方法。根據(jù)我給 JVM 的內(nèi)存量,它有時(shí)會(huì)在調(diào)整大小時(shí)失敗,有時(shí)會(huì)在 toRGB() 上失?。簆rivate MBFImage scaleImage2(float scaleFactor) throws IOException { FImage img2Flat = image2.flatten(); int width = (int)Math.round(img2Flat.getWidth() * scaleFactor); int height = (int)Math.round(img2Flat.getHeight() * scaleFactor); BilinearInterpolation resizer = new BilinearInterpolation(width, height, 1/scaleFactor); resizer.processImage(img2Flat); return img2Flat.toRGB();}這是我疊加圖像的地方:private MBFImage createScaledOverlay() { MBFImage scaledImg2 = null; if(scaledLastCrop == null) { try { scaledLastCrop = scaleLastCrop(); } catch (IOException e) { e.printStackTrace(); } } try { scaledImg2 = scaleImage2(image2ScaleFactor); } catch (IOException e) { e.printStackTrace(); } int img2ScaledPixelx = Math.round(image2SelectedPixel.x * image2ScaleFactor); int img2ScaledPixely = Math.round(image2SelectedPixel.y * image2ScaleFactor); int lastCropScaledPixelx = (int)Math.round(lastCropSelectedPixel.x * lastCropScaleFactor); int lastCropScaledPixely = (int)Math.round(lastCropSelectedPixel.y * lastCropScaleFactor); scaledImg2.overlayInplace(scaledLastCrop, img2ScaledPixelx - lastCropScaledPixelx, img2ScaledPixely - lastCropScaledPixely); return scaledImg2;}我可以選擇兩條前進(jìn)的道路之一:修復(fù) OutOfMemoryError疊加兩個(gè)圖像的另一種方法
1 回答

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
有時(shí)一個(gè)解決方案是如此明顯以至于令人尷尬。
現(xiàn)在想想,我真正的目標(biāo)是找到兩個(gè)圖像之間的比例因子。我可以縮小 image1,而不是放大 image2。這要少得多的內(nèi)存密集型。然后關(guān)于 image2 我可以反轉(zhuǎn)這個(gè)比例因子。
添加回答
舉報(bào)
0/150
提交
取消