How to find the center of a bright spot in an image?

Here is an example of the types of images that I will deal with:

Balls
(source: csverma at pages.cs.wisc.edu )

Each ball has one bright spot. I want to find the coordinates of the center of the bright spot. How can I do this in Python or Matlab? The problem that I am facing right now is that more than one point in place has the same (or approximately the same) white color, but I need to find the center of this “cluster” of white points.

Also, for the left and right images, how can I find the center of the whole circular object?

+5
source share
2 answers

, . , , . , , , , , , . . - MATLAB.

, , . 5 , , , , , :

im = imread('http://pages.cs.wisc.edu/~csverma/CS766_09/Stereo/callight.jpg');
im = rgb2gray(im);
im = imclearborder(im);

%// Split up images and place into individual cells
split_point = floor(size(im,2) / 5);
images = mat2cell(im, size(im,1), split_point*ones(5,1));

%// Show image to place dots
imshow(im);
hold on;

%// For each image...
for idx = 1 : 5
    %// Get image
    img = images{idx}; 

    %// Threshold
    thresh = img > 200;

    %// Find coordinates of thresholded image
    [y,x] = find(thresh);

    %// Find average
    xmean = mean(x);
    ymean = mean(y);

    %// Place dot at centre
    %// Make sure you offset by the right number of columns
    plot(xmean + (idx-1)*split_point, ymean, 'r.', 'MarkerSize', 18);
end        

:

enter image description here


Python, scikit-image numpy matplotlib . Python. , , , balls.jpg:

import skimage.io
import skimage.segmentation
import numpy as np
import matplotlib.pyplot as plt

# Read in the image
# Note - intensities are floating point from [0,1]
im = skimage.io.imread('balls.jpg', True)

# Threshold the image first then clear the border
im_clear = skimage.segmentation.clear_border(im > (200.0/255.0))

# Determine where to split up the image
split_point = int(im.shape[1]/5)

# Show image in figure and hold to place dots in
plt.figure()
plt.imshow(np.dstack([im,im,im]))

# For each image...
for idx in range(5):

  # Extract sub image
  img = im_clear[:,idx*split_point:(idx+1)*split_point]

  # Find coordinates of thresholded image
  y,x = np.nonzero(img)

  # Find average
  xmean = x.mean()
  ymean = y.mean()

  # Plot on figure
  plt.plot(xmean + idx*split_point, ymean, 'r.', markersize=14)

# Show image and make sure axis is removed
plt.axis('off')
plt.show()

:

enter image description here

regionprops ( MATLAB, scikit-image ). , regionprops, , , , .


, !

+7

, . (, exp) 2d-, . - conv2(exp(img),ker)

+1

All Articles