Code detecting false objects

1 回表示 (過去 30 日間)
learningmatlab
learningmatlab 2020 年 5 月 20 日
コメント済み: darova 2020 年 5 月 21 日
On the left is the original image and on the right objects are being detected. Please advise. Also, there is another image in which I use the same code and it detects only one object. Why is this happening? I have attached that image as well.
clear all
close all
img= imread("C:\Users\0000_012_14px_prergb.tif");
imshow (img)
img=rgb2gray(img);
b=imbinarize(img); %binary image
imshow(b)
img1 = bwareafilt(b,[20 1000]); %retains objects pixel area
c=bwlabel(img1);
imshow(c)
measurements = regionprops(c,img, 'MeanIntensity'); %measurements = regionprops(labeledImage, grayscaleImage, 'MeanIntensity');
stats = regionprops('table',img1,'Centroid','MajorAxisLength','MinorAxisLength') %object detection
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
hold on
viscircles(centers,radii); %drawing around the object
hold off
num_obj=height (stats)%finding the number of objects

回答 (1 件)

darova
darova 2020 年 5 月 20 日
Use threshold to find appropriate objects
th = threshold(img);
% bw = im2bw(img,th);
bw = im2bw(img,th+0.1);
  3 件のコメント
learningmatlab
learningmatlab 2020 年 5 月 21 日
編集済み: learningmatlab 2020 年 5 月 21 日
I have to analyze a set of images, will it work on all of them? These two images are from the same set. Also, there is no such function as "threshold" in Matlab.
darova
darova 2020 年 5 月 21 日
  • I have to analyze a set of images, will it work on all of them?
Yes
  • Also, there is no such function as "threshold" in Matlab.
Sorry, i mean graythresh()

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by