How can I solve this - Undefined operator '.^' for input arguments of type 'struct'. ?

1 次查看(过去 30 天)
clc;
close all;
clear all;
Im = imread('B1_16.tif');
I=rgb2gray(Im);
I=adapthisteq(I);
[row col]=size(I)
double(I);
figure
imshow(I)
% DoG filter (to improve the edge)
sigma = 4;
gauss1 = fspecial('gaussian', round([10*sigma 10*sigma]), sigma);
sigma = 0.1;
gauss2 = fspecial('gaussian', round([10*sigma 10*sigma]), sigma);
blur1 = imfilter(I, gauss1, 'replicate', 'same');
blur2 = imfilter(I, gauss2, 'replicate', 'same');
dog = blur1 - blur2;
figure
imshow(dog)
str = 'Click to select initial contour location. Double-click to confirm and proceed.';
title(str,'Color','b','FontSize',12);
disp(sprintf('\nNote: Click close to object boundaries for more accurate result.'));
% Select region interactively
mask = roipoly;
figure, imshow(mask)
title('Initial MASK');
% Segment the image using active contours
maxIterations = 1; % More iterations may be needed to get accurate segmentation.
bw = activecontour(I, mask, maxIterations, 'Chan-Vese');
% Display segmented image
figure, imshow(bw)
title('Segmented Image');
% find the features of the segmented area using function
g=regionprops(bw,'all')
% finding the area of the white area segmented from the previous images
% area is the number of white pixel in the image
numofpixels=sum(bw(:))% correct (num of pixels indicates the area of the segmented image)
% numofpixels1=sum(I(:)) just to confirm that the algorithm used is
% correct
% measure the perimeter
Perimeter=regionprops(bw,'perimeter')
% determine the circularities
Circularities=Perimeter.^2/(4*pi*numofpixels)
%perimeter
pm=bwperim(bw,8)
red=Im(:,:,1);
green=Im(:,:,2);
blue=Im(:,:,3);
red(pm)=255;
green(pm)=255;
blue(pm)=0;
out=cat(3,red,green,blue);
figure
imshow(pm)
figure
imshow(out)

采纳的回答

Walter Roberson
Walter Roberson 2017-11-25
Change
Perimeter=regionprops(bw,'perimeter')
to
rinfo = regionprops(bw,'perimeter');
Perimeter = [rinfo.Perimeter];
  3 个评论
Walter Roberson
Walter Roberson 2017-11-25
regionprops will return a structure array with one element for each region found. You asked for perimeter so there will be one field, rinfo(1).Perimeter, rinfo(2).Perimeter and so on existing
When you name a structure array and a field, rinfo.Perimeter, then MATLAB converts that into a comma separated list, as if you had written rinfo(1).Perimeter, rinfo(2).Perimeter and so on at that point. With [] there, that becomes
Perimeter = [rinfo(1).Perimeter, rinfo(2).Perimeter, ....]
which is the horizontal concatenation of the Perimeter values for all of the elements. The effect is the same as
for K = 1 : length(rinfo)
Perimeter(K) = rinfo(K).Perimeter;
end
since all of the items are scalar.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computational Geometry 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by