【问题标题】:How to average multiple images in matlab?如何在matlab中平均多个图像?
【发布时间】:2011-04-16 21:09:55
【问题描述】:

我正在尝试从 1000 帧中获取平均图像。

  • 每张图片大小为 512 x 512 像素。我从实验中得到的文件是 tiff 单元 16 数据。
  • tiff 文件包含 1000 个相同点的帧。

我正在考虑编写一个 m 文件,从 tiff 文件中读出 1000 帧,然后对它们进行平均,但它似乎会很快耗尽内存。

获得这 1000 帧的平均图像的更好方法是什么。如果唯一的方法是在将所有帧加载到 matlab 后对它们进行平均,我应该如何平均超过 1000 帧? 谢谢。

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    尝试以下方法:

    a=zeros(512);
    for i=1:1000
        a=a+frame(i);
    end
    a=a/1000;
    

    a 是帧的平均值。

    【讨论】:

      【解决方案2】:

      读取每个图像后,您可以将其累积在临时变量中,即在每个步骤中将当前图像添加到该变量中。读取所有图像后,累加器将存储所有图像的总和。最后除以图片的数量,就得到了最终的图片。

      但重要的是图像通常存储为 uint8(无符号 8 位整数)。而且如果加起来,就会发生溢出。为了防止这种累加器应该是例如uint32 或双精度。如果希望最终图像为 uint8,则需要显式转换。

      【讨论】:

      • 您好 user502144,感谢您的快速回复。我想在平均处理之后将文件保存在第 16 单元中。不太明白你说的临时变量是什么意思,具体是怎么做的?
      【解决方案3】:
      % slight modiifcations to the last answer
      if the files are named image1.tif, image2.tif,....image1000.tif)
      im = imread('image1.tif');
      for i = 2:1000
      im = imadd(im,imread(sprintf('image%d.tif',i)));
      end
      im = im/1000;
      imshow(im,[]);
      

      当你的名字像 image00001, image00002,....image00010,...image00100,.... 这里只是从一个循环中的 2-10 读取另一个循环中的 11-99 等等时,问题变得有趣了。 ..希望它有所帮助

      【讨论】:

      • 为什么最终的平均图像是暗的?
      • 这取决于您如何显示图像。如果您的图像的位深度(= 灰度范围)大于您的查看器(或屏幕)可以显示的位深度,那么您将看不到任何东西。尝试使用 ImageJ 显示您的图像以进行检查。
      【解决方案4】:
      source = 'D:\file_path\'; %'
      im_number=262; % image number should not exceed 16 843 009 images
      sum=uint32(imread([source,'image1.bmp'],'bmp')); % converts image array to Unsigned 32-bit integer to escape overflow
        for n=2:im_number;
            sum=imadd(sum,uint32(imread([source,'image', num2str(n),'.bmp'],'bmp'))); % perform addition without overflow
      %      using images specific function imadd
        end;
        sum = imdivide(sum,im_number); % performing normalization of addition using images specific function imdivide
        imshow(uint8(sum),[]); % displais the image converted back to Unsigned 8-bit integer
        imwrite(uint8(sum),[source,'sum_image.bmp'],'bmp');  % saves the averaged image
      

      【讨论】:

        【解决方案5】:
        % assuming there are files named: '1.tif','2.tif',...'1000.tif'
        im = imread('1.tif');
        for i = 2:1000
         im = imadd(im,imread(sprintf('%d.tif',i)));
        end
        im = im/1000;
        imshow(im,[]);
        

        【讨论】:

          【解决方案6】:
          J=0;
          for i =1:index %index is the number of images to be averaged
              I=uint32(imread(['frame',num2str(i),'.bmp']));
              J=imadd(I,J);
          end
          J=floor(J/index);
          J=uint16(J); %J is the required image
          

          【讨论】:

          • 请描述你的答案
          猜你喜欢
          • 2012-04-21
          • 1970-01-01
          • 1970-01-01
          • 2018-06-08
          • 1970-01-01
          • 2016-10-31
          • 1970-01-01
          • 1970-01-01
          • 2014-08-02
          相关资源
          最近更新 更多