how to calculate the center of an object in binary image
Mostra commenti meno recenti
hellow dears i need support to calculate the center of an object in binary image, the binary image has only one object so that i need to find the center of that object in order to crop the object from the binary image as in attached image
Risposta accettata
Più risposte (2)
haider alnaqeeb
il 27 Feb 2016
0 voti
Walter Roberson
il 27 Feb 2016
0 voti
Use regionprops() and ask for Centroid
7 Commenti
haider alnaqeeb
il 27 Feb 2016
Walter Roberson
il 27 Feb 2016
YourImage = imread('aaaaa.png');
bw = im2bw(YourImage);
info = regionprops(bw, 'Centroid');
Image_Center = info.Centroid;
%now display it visually
image(bw)
colormap(gray(2))
scatter(Image_Center(1), Image_Center(2), 'r*')
haider alnaqeeb
il 27 Feb 2016
Walter Roberson
il 27 Feb 2016
x_left = Image_Center(1) - 160/2;
y_bottom = Image_Center(2) - 480/2;
pos = [x_left y_bottom 160 480];
cropped = imcrop(YourImage, pos);
haider alnaqeeb
il 27 Feb 2016
haider alnaqeeb
il 27 Feb 2016
Walter Roberson
il 27 Feb 2016
regionprops should already act that way.
Note: the page you posted, aaaaa.png, has two or more blobs, because it has the grayscale image at the left and the diagram at the right. You need to be operating on just the grayscale image.
Categorie
Scopri di più su Red in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
