I'm working with a particular type of images. Those, after obtaining the spectrum (aply the fft), I obtain the following picture:
So I want to select one of those "points" (called orders of the spectrum), at the following way:
I mean "draw" a circle aroud it, select the pixels inside and then center those pixels(without the "border circle"):
How can I perform it using OpenCV? Does exist any function?
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:
Another edit: This might be useful for finding your peaks.
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?!?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With