# How to find the center position under the saturation spot signal

5 vues (au cours des 30 derniers jours)
Tina Hsiao le 9 Avr 2021
Commenté : Tina Hsiao le 9 Avr 2021
Hello, I would like to seek your help. I have an image below. How can I find the spot position centre (X,Y) under the saturation spot signal?
The code as below
clear all; close all;clc
S = dir(fullfile(D,'*.bmp')); % pattern to match filenames.
%%-------open file----
S_BG = dir(fullfile(D,'figure.bmp')); % pattern to match filenames.
for k_BG = 1:numel(S_BG)
F_BG = fullfile(D,S_BG(k_BG).name);
Z = im2double(I_BG);
Z = rgb2gray(Z);
figure(100),imshow(Z)
figure(101)
surf(Z)
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Steve Eddins le 9 Avr 2021
Try converting the image to binary using imbinarize and then using regionprops to compute the centroid.
I = rgb2gray(rgb);
bw = imbinarize(I);
s = regionprops(bw,'Centroid')
s = struct with fields:
Centroid: [202.0826 195.7218]
imshow(I,'InitialMagnification','fit')
hold on
plot(s.Centroid(1),s.Centroid(2),'b*')
hold off
Alternatively, consider computing a weighted centroid using the grayscale pixel values. First, expand the binarized object using dilation to include more of the grayscale pixel values at the edge of the object.
bw2 = imdilate(bw,strel('disk',20));
s2 = regionprops(bw2,I,'WeightedCentroid')
s2 = struct with fields:
WeightedCentroid: [202.0307 195.3167]
imshow(I,'InitialMagnification','fit')
hold on
plot(s2.WeightedCentroid(1),s2.WeightedCentroid(2),'b*')
hold off
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Tina Hsiao le 9 Avr 2021
Thanks a lot.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by