简体   繁体   English

ImageJ API:合并图像

[英]ImageJ API: Combining images

Using the ImageJ api, I'm trying to save an composite image, made up of several images laid out side by side. 我试图使用ImageJ api保存一个合成图像,该图像由并排放置的多个图像组成。

I've got code that loads ImagePlus objs, and saves them. 我有加载ImagePlus objs并保存它们的代码。 But I can't figure how to paste an image into another image. 但是我不知道如何将一个图像粘贴到另一个图像中。

I interpret the problem as taking multiple images and stitching them together side by side to form a large one where the images may have different dimensions. 我将问题解释为拍摄多张图像并将它们并排缝合在一起以形成较大的图像,其中图像可能具有不同的尺寸。 The following incomplete code is one way of doing it and should get you started. 以下不完整的代码是执行此操作的一种方法,应该使您入门。

public ImagePlus composeImages(ArrayList<ImagePlus> imageList){
    int sumWidth = 0;
    int maxHeight = 0;

    for(ImagePlus imp : imageList){
        sumWidth = sumWidth +imp.getWidth();
        if(imp.getHeight() > maxHeight)
            maxHeight = imp.getWidth();

    }

    ImagePlus impComposite = new ImagePlus();

    ImageProcessor ipComposite = new ShortProcessor(sumWidth, maxHeight);

    for(int i=0; i<sumWidth; i++){
        for(int j=0; j<sumWidth; j++){

            ipComposite.putPixelValue(i, j, figureOutThis);

        }
    }

    impComposite.setProcessor(ipComposite);
    return impComposite;

}

You need to write an algorithm to find the pixel value ( figureOutThis ) to put in the composite image at i , j . 您需要编写一种算法来查找要放入合成图像ij的像素值( figureOutThis )。 That is pretty trivial if all images have the same width and a little bit more work otherwise. 如果所有图像都具有相同的宽度,否则工作量会很小。 Happy coding 快乐编码

Edit: I should add that I am assuming they are also all short images (I work with medical grayscale). 编辑:我应该补充一点,我假设它们都是短图像(我使用医学灰度)。 You can modify this for other processors 您可以为其他处理器修改它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM