【发布时间】: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 循环的原因。
【问题讨论】: