


How to extract two circular areas from a 9000x7000 pixel image using Python and OpenCV?
Apr 01, 2025 pm 09:42 PMPython and OpenCV efficiently extract two circular areas in 9000x7000 pixel images
Processing ultra-high resolution images (such as 9000x7000 pixels) and extracting specific shapes (such as circles) from them is a common challenge in image processing and computer vision. This article provides a solution using Python and OpenCV libraries to efficiently and accurately extract target circular areas.
The problem with the existing code is that there are too many circles detected and it is impossible to accurately select the two circle areas required. For improvement, we will adopt the following strategies:
- Image Preprocessing: Scaling and Noise Reduction : First, to improve processing efficiency, we reduce the original image to the right size. At the same time, a Gaussian blur filter is applied to reduce image noise, thereby improving the accuracy of circular detection.
import cv2 import numpy as np image_path = r"c:\users\17607\desktop\smls pictures\pic_20231122151507973.bmp" # Read image img = cv2.imread(image_path) # Zoom the image (adjust the zoom ratio according to the actual situation) scale_percent = 10 # Scale to 1/10 of the original image width = int(img.shape[1] / scale_percent) height = int(img.shape[0] / scale_percent) dim = (width, height) resized_img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA) # grayscale conversion gray = cv2.cvtColor(resized_img, cv2.COLOR_BGR2GRAY) # GaussianBlurred = cv2.GaussianBlur(gray, (5, 5), 0)
- Edge detection: Canny algorithm : Use the Canny edge detection algorithm to extract image edge information and prepare for subsequent circular detection.
# Canny edge detection edges = cv2.Canny(blurred, 50, 150)
- Circle detection: Hough Transform : Use Hough Circle transformation to detect circles in images. The key is parameter adjustments to ensure that only the two circles we need are detected. Here we filter according to the radius of the circle and select the two largest circles.
# HoughCircle Transform Circles = cv2.HoughCircles(edges, cv2.HOUGH_GRADIENT, 1, 40, param1=50, param2=30, minRadius=0, maxRadius=0) If circles is not None: circles = np.uint16(np.around(circles)) # Select two largest circles = circles[0, :] circles = circles[np.argsort(circles[:, 2])[::-1][:2]] # Select two circles with the largest radius for i in circles: center_x, center_y, radius = i # Draw circle cv2.circle(resized_img, (center_x, center_y), radius, (0, 0, 255), 2) cv2.circle(resized_img, (center_x, center_y), 2, (255, 0, 0), 3) cv2.imshow("Detected Circles", resized_img) cv2.waitKey(0) cv2.destroyAllWindows()
Through the above steps, we can effectively extract the two largest circular regions from high-resolution images and verify them by visualization results. It should be noted that the parameters of scale_percent
and Hough transformation need to be adjusted according to the actual image to achieve the best detection effect. If two circles are of similar size, a more refined choice may be required based on the center coordinates or other features.
The above is the detailed content of How to extract two circular areas from a 9000x7000 pixel image using Python and OpenCV?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

ToresolvenetworkconnectivityissuesinWindows,resettheTCP/IPstackbyfirstopeningCommandPromptasAdministrator,thenrunningthecommandnetshintipreset,andfinallyrestartingyourcomputertoapplychanges;ifissuespersist,optionallyrunnetshwinsockresetandrebootagain

EnableAppLockerviaGroupPolicybyopeninggpedit.msc,navigatingtoApplicationControlPolicies,creatingdefaultrules,andconfiguringruletypes;2.Createcustomrulesusingpublisher,path,orhashconditions,preferringpublisherrulesforsecurityandflexibility;3.Testrules

Use multiprocessing.Queue to safely pass data between multiple processes, suitable for scenarios of multiple producers and consumers; 2. Use multiprocessing.Pipe to achieve bidirectional high-speed communication between two processes, but only for two-point connections; 3. Use Value and Array to store simple data types in shared memory, and need to be used with Lock to avoid competition conditions; 4. Use Manager to share complex data structures such as lists and dictionaries, which are highly flexible but have low performance, and are suitable for scenarios with complex shared states; appropriate methods should be selected based on data size, performance requirements and complexity. Queue and Manager are most suitable for beginners.

Weakreferencesexisttoallowreferencingobjectswithoutpreventingtheirgarbagecollection,helpingavoidmemoryleaksandcircularreferences.1.UseWeakKeyDictionaryorWeakValueDictionaryforcachesormappingstoletunusedobjectsbecollected.2.Useweakreferencesinchild-to

VerifytheWindowsISOisfromMicrosoftandrecreatethebootableUSBusingtheMediaCreationToolorRufuswithcorrectsettings;2.Ensurehardwaremeetsrequirements,testRAMandstoragehealth,anddisconnectunnecessaryperipherals;3.ConfirmBIOS/UEFIsettingsmatchtheinstallatio

1. Binance is a leading platform with global trading volume. It is known for its rich currency, diverse trading models and Launchpad financing services. It has a wide global layout; 2. OKX is famous for its innovative financial derivatives and high security, and actively deploys the Web3 ecosystem; 3.gate.io has a long history and provides more than 1,000 currency transactions, with stable systems and strict risk control; 4. Huobi provides diversified trading services, strong research strength, and pays attention to compliance and security; 5. KuCoin is known as the "national trading platform", attracting investors with low fees and high returns potential projects, and has fast customer service response; 6. Kraken is a well-known American exchange with strict security measures, supporting fiat currency transactions, and has high compliance; 7. Bitstamp is a veteran European platform, serving

Use boto3 to upload files to S3 to install boto3 first and configure AWS credentials; 2. Create a client through boto3.client('s3') and call the upload_file() method to upload local files; 3. You can specify s3_key as the target path, and use the local file name if it is not specified; 4. Exceptions such as FileNotFoundError, NoCredentialsError and ClientError should be handled; 5. ACL, ContentType, StorageClass and Metadata can be set through the ExtraArgs parameter; 6. For memory data, you can use BytesIO to create words

This is a simple login example based on Flask-Login, including user login, session management, and login protection routing. 1. Install flask and flask-login dependencies; 2. Create app.py file and configure Flask-Login, simulate user data and login callbacks; 3. Implement login, logout and protected dashboard routing; 4. Use the template files login.html and dashboard.html for page rendering; 5. Log in with the user name admin and password password123 after running the application. The complete process covers flash messages, form processing and session retention, which is suitable for beginners to quickly master the Flask login mechanism. It is recommended to introduce the database in the future.
