【问题标题】:Extract multiple ROI pixel value from multiple images从多个图像中提取多个 ROI 像素值
【发布时间】:2013-11-19 02:23:31
【问题描述】:

我遇到的编程挑战超出了我结结巴巴的 Matlab 专业知识的能力范围。我有一个单元格数组中的图像列表和 ROI 掩码列表,我想分别提取每个 ROI 的平均像素值, 我的代码是这样的:

files=dir('*.tif');
for f=1:length(files)
image=im2double(imread(files(f).name));       
pixel_value(:,f)=cellfun(@(x) extractROIpixel(x,image), mask);    
% apply extractROIpixel on each cell of the mask array
end

function [ mean_pixel_value ] = extractROIpixel( mask, img )
      mask=im2double(mask);
      mask(mask == 0) = NaN;
      mask_area=mask.*img;
      mean_pixel_value=mean(mask_area(~isnan(mask_area)));  
end

这可行,但速度很慢(

【问题讨论】:

    标签: matlab mask roi


    【解决方案1】:

    怎么样:

    files=dir('*.tif');
    for f=1:length(files)
       image=im2double(imread(files(f).name));
       masked=cellfun(@(x) image.*x, mask);
       stats{f}=cellfun(@(x) regionprops(x, 'MeanIntensity'), masked);
    end
    

    我没有对这两种方法进行基准测试,所以我不知道它是否更有效。

    【讨论】:

    • 感谢您的快速回答,但它无法正常工作,因为我想在同一图像中对我的掩码数组的每个单元格应用“掩码”函数:换句话说,我必须在整个掩码数组中应用函数,保持图像不变并迭代我的所有图像。因此我在图像列表上的“for”循环。
    • 我明白了。我相应地对其进行了编辑。同样,我不知道regionprops 是否有效。
    • 感谢您指出我不知道的 regionprops 方法...但它实际上比我的 extractROIpixel 函数花费的时间要多一倍。
    • 好的,很高兴知道。这很方便,但显然不是很精简。
    猜你喜欢
    • 2019-07-17
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多