Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point detection and circle area selection

I'm working with a particular type of images. Those, after obtaining the spectrum (aply the fft), I obtain the following picture:

enter image description here

So I want to select one of those "points" (called orders of the spectrum), at the following way:

enter image description here

I mean "draw" a circle aroud it, select the pixels inside and then center those pixels(without the "border circle"):

enter image description here

How can I perform it using OpenCV? Does exist any function?

like image 779
FacundoGFlores Avatar asked Mar 19 '23 07:03

FacundoGFlores


2 Answers

EDIT: As per discussion below, to 'select' a circle, a mask can be used:

# Build mask
mask = np.zeros(image_array.shape, dtype=np.uint8)
cv2.circle(mask, max_loc, circle_radius, (255, 255, 255), -1, 8, 0)

# Apply mask (using bitwise & operator)
result_array = image_array & mask

# Crop/center result (assuming max_loc is of the form (x, y))
result_array = result_array[max_loc[1] - circle_radius:max_loc[1] + circle_radius,
                            max_loc[0] - circle_radius:max_loc[0] + circle_radius, :]

This leaves me with something like:

Masked and cropped image

Another edit: This might be useful for finding your peaks.

like image 197
Pokey McPokerson Avatar answered Mar 21 '23 22:03

Pokey McPokerson


Not sure if that's what you asked, but if you just want to center around such a point, you can do it with subregions:

cv::Point center(yourCenterX_FromLeft, yourCenterY_fromTop);
int nWidth = yourDesiredWidthAfterCentering;  // or 2* circle radius
int nHeight= yourDesiredHeightAfterCentering; // or 2* circle radius

// specify the subregion: top-left position and width/height
cv::Rect subImage = cv::Rect(center.x-nWidth/2, center.y-nHeight/2, nWidth, nHeight);

// extract the subregion out of the original image. remark that no data is copied but original data is referenced
cv::Mat subImageCentered = originalImage(subImage);

cv::imshow("subimage", subImageCentered);

didnt test, but that should be ok.

EDIT: sorry, it's c++ but I think subregions will work similar in python?!?

like image 43
Micka Avatar answered Mar 21 '23 22:03

Micka