首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageJ接口:拼图

ImageJ接口:拼图
EN

Stack Overflow用户
提问于 2012-09-04 00:36:02
回答 2查看 2.4K关注 0票数 0

使用ImageJ应用程序接口,我尝试保存一个合成图像,它由几个并排排列的图像组成。

我有加载ImagePlus对象并保存它们的代码。但是我不知道如何将一个图像粘贴到另一个图像中。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-04 20:41:49

我将这个问题解释为将多个图像并排拼接在一起,形成一个大图像,其中图像可能具有不同的尺寸。以下不完整的代码是一种方法,应该可以帮助您入门。

代码语言:javascript
复制
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;

}

您需要编写一个算法来查找要放入ij处的合成图像的像素值(figureOutThis)。如果所有图像都具有相同的宽度,这是相当微不足道的,否则就需要做更多的工作。快乐编码

编辑:我应该补充说,我假设它们也都是短图像(我使用的是医学灰度)。您可以为其他处理器修改此设置

票数 1
EN

Stack Overflow用户

发布于 2021-05-28 11:48:54

此代码组合/缝合图像网格:

它假设图像都具有相同的尺寸。

代码语言:javascript
复制
  ImagePlus combine(List<List<ImagePlus>> imagesGrid) {
    checkArgument(
        !imagesGrid.isEmpty() && !imagesGrid.get(0).isEmpty(), "Expected grid to be non-empty");
    checkArgument(
        imagesGrid.stream().map(List::size).distinct().count() == 1,
        "Expected all rows in the grid to be of the same size");
    checkArgument(
        imagesGrid.stream().flatMap(List::stream).map(ImagePlus::getWidth).distinct().count() == 1,
        "Expected all images to have the same width");
    checkArgument(
        imagesGrid.stream().flatMap(List::stream).map(ImagePlus::getHeight).distinct().count() == 1,
        "Expected all images to have the same height");

    int rows = imagesGrid.size();
    int cols = imagesGrid.get(0).size();

    int singleWidth = imagesGrid.get(0).get(0).getWidth();
    int singleHeight = imagesGrid.get(0).get(0).getHeight();

    int combinedWidth = singleWidth * cols;
    int combinedHeight = singleHeight * rows;

    ImageProcessor processor = new ColorProcessor(combinedWidth, combinedHeight);

    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < cols; col++) {
        ImagePlus image = imagesGrid.get(row).get(col);
        int offSetWidth = col * singleWidth;
        int offsetHeight = row * singleHeight;
        for (int w = 0; w < singleWidth; w++) {
          for (int h = 0; h < singleHeight; h++) {
            processor.putPixel(w + offSetWidth, h + offsetHeight, image.getPixel(w, h));
          }
        }
      }
    }

    ImagePlus combinedImage = new ImagePlus();
    combinedImage.setProcessor(processor);
    return combinedImage;
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12251475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档