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)
MATLAB: How to solve this – Undefined operator ‘.^’ for input arguments of type ‘struct’.
structstuct errorundefined operator
Best Answer