Can I use regionprops two times with two different variables in the same program at time?

조회 수: 1 (최근 30일)
if true
clc;
close all;
clear;
workspace;
folder = pwd;
% folder = pwd;
filepattern = fullfile(folder, '*.png');
srcFiles = dir(filepattern);
numImages = length(srcFiles);
for k = 1 : numImages
fullFileName = fullfile(folder, srcFiles(k).name);
a = imread(fullFileName);
bwimg =bwareafilt(~a, 1);
s=regionprops(bwimg,'Orientation');
theta = s(1).Orientation;
if theta>=0 && theta<90
phi=90-theta;
Y=imrotate(bwimg,phi);
else
phi=90+theta;
Y=imrotate(bwimg,-phi);
end
s1=regionprops(Y,'Centroid','BoundingBox','MajorAxisLength','MinorAxisLength');
circleCenterX = s1.Centroid(1);
circleCenterY= s1.Centroid(2);
diameters = mean([s1.MajorAxisLength s1.MinorAxisLength],2);
end
end
This is showing me error that multiple field reference. I am first rotating the images then again taking its property as centroid and orientation has been changed from the original image but its not working.
  댓글 수: 4
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 9월 18일
편집: KALYAN ACHARJYA 2018년 9월 18일
Have you checked this code with the single image file (remove loop)?
Matt J
Matt J 2018년 9월 18일
This is showing me error that multiple field reference.
You need to show that error to us, too.

댓글을 달려면 로그인하십시오.

답변 (1개)

Saurabh Patel
Saurabh Patel 2018년 9월 19일
편집: Walter Roberson 2018년 9월 19일
Probably following lines have error.
circleCenterX = s1.Centroid(1); circleCenterY= s1.Centroid(2);
s1 might be nx1 struct with n greater than 1. My guess is bwareafilt is producing an oversegmented object. You can try the following:
Area = [s1.Area];
index = find(Area==max(Area));
circleCenterX = s1(index).Centroid(1);
circleCenterY= s1(index).Centroid(2);
diameters = mean([s1(index).MajorAxisLength s1(index).MinorAxisLength],2);
  댓글 수: 3
Saurabh Patel
Saurabh Patel 2018년 9월 19일
I'm not sure what's happening there. regionprops should not return 2x1 struct without any values. If image was empty, it should have returned an empty struct (0x1).
Zara Khan
Zara Khan 2018년 9월 19일
Yaa this is happening.For few images I am getting only 2×1 struct only. If I use imcomplement instead of bwareafilt then also I am getting the same thing

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by