How can I solve this - Undefined operator '.^' for input arguments of type 'struct'. ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
matlab noob
el 25 de Nov. de 2017
Comentada: matlab noob
el 25 de Nov. de 2017
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)
0 comentarios
Respuesta aceptada
Walter Roberson
el 25 de Nov. de 2017
Change
Perimeter=regionprops(bw,'perimeter')
to
rinfo = regionprops(bw,'perimeter');
Perimeter = [rinfo.Perimeter];
3 comentarios
Walter Roberson
el 25 de Nov. de 2017
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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!