【问题标题】:regionprops detects only one component, while there are multiple white regions in the BW imageregionprops 只检测到一个分量,而 BW 图像中有多个白色区域
【发布时间】:2021-02-28 00:27:53
【问题描述】:

我是图像处理的初学者,我正在尝试使用 regionprops 函数,但是我每次使用它时都只得到一个值,即使图像中有 20 个对象(单元格)。

这是我在 MATLAB 中处理的代码:

    close all 
    clc
    clear all
    control = {};
    test={};
    se90 = strel('line',8,90);
    se0 = strel('line',8,0);
    fudgeFactor = 1.7;
    seD = strel('diamond',1);
    avgfilter =fspecial('average');% average filter
    location_control = '\\tsclient\c\cell_morphology\control\';
    list_control=dir([location_control, '*.tif']);
    for k = 1:1
        thisfig = figure();
        control=[control,double(imread([location_control list_control(k).name]))];
        con{k} = uint8(control{k});
        BandW{k} = rgb2gray(con{k}); % turn the image from RGB into gray 
        %smoothing:
        lowhigh{k} = imadjust(BandW{k},stretchlim(BandW{k}),[]);
        fltcon{k} = imfilter(lowhigh{k},avgfilter);
        [~,threshold] = edge(lowhigh{k},'sobel');
        BWs{k} = edge(fltcon{k},'sobel',threshold * fudgeFactor);%binary gradient mask
        % dilation:
        BWsdil{k} = imdilate(BWs{k},[se90 se0]);
        %filling gapes
        BWdfill{k} = imfill(BWsdil{k},'holes');
        % removing irregular cells:
        BWcleaned{k} = bwpropfilt(BWdfill{k},'Perimeter',12);
        BWcleaned2{k} = bwpropfilt(BWdfill{k},'Eccentricity',2); % detects elongated cells 
        zerones{k} =  im2bw(BWcleaned{k}); % convert the matrix to 1s and 0s. 
        revzerones{k} =  1- zerones{k}; 
        clean{k} = BWdfill{k} .* revzerones{k}+ BWcleaned2{k};
        %smooth objects
        BWfinal{k} = imerode(clean{k},seD);
        BWfinal{k} = imerode(BWfinal{k},seD);
        %clean borders:
        BWnobord{k} = imclearborder(BWfinal{k},4);
        %Visualization of the Segmentation
        final{k} = labeloverlay(lowhigh{k},BWnobord{k});
        imshow(final{k});
        title(sprintf('image %d',k));
        [~, num{k}] = bwlabel(pdilate{k}); %counts the number of cells in image k 
        pdilate{k} = imdilate(BWnobord{k},[se90 se0]);
%reginprops code: 
        charc{k} = regionprops('table',pdilate{k},'Area','MinorAxisLength','MajorAxisLength', 'Perimeter');
        Areas{k} = [charc{k}.Area];
        Perim{k} = [charc{k}.Perimeter];
        MJax{k} = [charc{k}.MajorAxisLength];
        MNax{k} = [charc{k}.MinorAxisLength];
  
    end

我尝试了不同的方法让它工作,但每次只返回一个值,在这种情况下可以做什么?

这是我正在处理的图像之一,由于网站的限制,它的分辨率较低,总共有 10 张图像,这就是我使用 for 循环的原因。

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    这是因为您将logical 以外的类型的图像传递给regionprops。从clean{k} = BWdfill{k} .* revzerones{k}+ BWcleaned2{k}; 行开始,图像被转换为​​双倍。所以regionprops 假设图像包含区域标签(如stats = regionprops(L,properties))。但由于所有非零像素的值为 1,它只检测一个区域并返回其属性。试试:

    charc{k} = regionprops('table',pdilate{k}, 'Image');
    imshow(charc{k}.Image{1})
    

    要解决此问题,您可以将 clean 转换为 logical

    clean{k} = logical(BWdfill{k} .* revzerones{k}+ BWcleaned2{k});
    

    ,或者把传给regionprops的图片隐藏起来:

    charc{k} = regionprops('table',pdilate{k}>0,'Area','MinorAxisLength','MajorAxisLength', 'Perimeter');
    

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 2021-07-31
      • 2021-03-21
      • 1970-01-01
      相关资源
      最近更新 更多