I have an image that contains more than one rois //non-rectangular// in a transparent image.. plz help me how to extract those rois as induvidual roi image
how to Extract rois as induvidual roi images
218 views Asked by Bharath Kumar At
2
There are 2 answers
4
Bharath Kumar
On
import numpy as np
import matplotlib.pyplot as plt
!mkdir /content/test
!rm -r /content/test/*
image = cv2.imread('/content/test.png')
original = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
canny = cv2.Canny(blurred, 120, 255, 1)
kernel = np.ones((5,5),np.uint8)
dilate = cv2.dilate(canny, kernel, iterations=1)
# Find contours
cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
# Iterate thorugh contours and filter for ROI
image_number = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
#cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)
ROI = original[y:y+h, x:x+w]
#cv2.imwrite("/content/test/ROI_{}.png".format(image_number), ROI)
image_number += 1
## (4) Create mask and do bitwise-op
mask = np.zeros(image.shape[:2],np.uint8)
cv2.drawContours(mask, [c],-1, 255, -1)
dst = cv2.bitwise_and(image, image, mask=mask)
## Save it
#cv2.imwrite("dst.png", dst)
cv2.imwrite("/content/test/ROI_{}.png".format(image_number), dst)
image_number += 1
# cv2.imshow('canny', canny)
# cv2.imshow('image', image)
# cv2.waitKey(0)
plt.imshow(canny)
plt.imshow(image)here
Related Questions in IMAGE
- Add image to JCheckBoxMenuItem
- Display images on Django Template Site
- How to resize images with PHP PARSE SDK
- Animation in Java on top of JPanel
- Slow performance on ipad erasing image
- What are the pros and cons of the picture element?
- Carrierwave file upload with different file types
- How to use annotorious with angular
- Images not showing when uploaded to server
- ImageView doesn't show up
- Image Resizing adjusts ratio
- Displaying bitmap image on Android (OpenCV)
- Class 'Imagick' not found - PHP and Windows
- Image position - randomly select position
- Replace image 1 with image 2 after 5 sec
Related Questions in IMAGE-PROCESSING
- Need help in detecting multiple blobs
- Image based steganography that survives resizing?
- WinRT Extract Thumbnail from RAW image format
- 3D B-Spline approximation
- Qualitative and Quantitative analysis of filtered back projection / iradon in matlab
- How to detect objects in an image based on colour?
- How to make sense (handle) when computes logarithm of zero in prior information
- scilab - Drawing bounding box
- Lowpass filter non working
- Get a single line representation for multiple close by lines clustered together in opencv
- error while drawing several x-marks on a binary image in matlab
- Which method should I use to find gradient direction of pixels in an image?
- Finding Circle Boundary Pixels Coordinates and RGB Intensity Values from An RGB Input Image in Matlab
- using SURF for handdetection
- Using only one tool from CLImageEditor
Related Questions in EXTRACT
- Python: How to extract data in text file based on class information from another text file?
- Extract method names from .CS code files
- Node js Separate String into arrays
- How to extract data from web api with Talend Open Studio
- Extract as.numeric value from CSV
- Download zip file, extract and overwrite windows 2008 r2
- extract numerical values from DataFrame string object
- Extract Images from Executable Files Using Managed Code (C#/VB)
- Incorrect Extraction of fields in Splunk
- How to extract short sequence using window with specific step size?
- Extract rows based on values from text file using Python
- XmlPullParser : extract tags in Tag
- Extracting Table Data using JSoup
- Extracting Substring from File Name
- How to extract short sequence based on step size?
Related Questions in OPENCV
- segmentation fault: 11, extracting data in vector
- Disable OpenCL in OpenCV completely
- Python - Writing your own function with opencv giving an error
- Opengl Augmented Reality in Android from solvepnp
- OpenCv Multispectral Image openCV
- Displaying bitmap image on Android (OpenCV)
- Applying homography on non planar surface
- BackgroundSubtractor getBackgroundImage() function return empty Image
- How to choose good SURF feature keypoints?
- opencv python error: Assertion failed (size.width>0 && size.height>0)
- CIDetector to filter rectangle and get cropped image
- How to detect squares in video with OpenCV?
- Python OpenCV error: (-215) size.width>0 && size.height>0 in function imshow
- OpenCV algorithm of contours searching and creation of bounding rectagle
- OpenCV Opening/Closing shifts the positions of the pixels
Related Questions in ROI
- How to create rotated rectangular or polygonal ROI/mask?
- ROI selection in ImageJ macro
- Matlab: how to save the image result Real-time plotting of ROI selected with IMRECT
- Matlab ROI Image Processing Approach
- imageJ/FIJI: can i add a new ROI in the middle of a ROI manager list of ROIs
- Using ROI in MATLAB
- Image Filter on ROI with Java2D
- Converting location into binary masks and filtering the image with such masks
- My confusion with region of interest
- Custom Region of Interest
- Working with Opencv Sobel results
- Submatrix out of bounds (OpenCV)
- Spatial Transform to ROI in MATLAB
- how to Extract rois as induvidual roi images
- Python ROI not being croped properly from contour
Related Questions in PYTHON
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)

contoursof the image.Result:
Now we are sure, we have detected all the contours in the image, we can save them individually.
Get the coordinates of each
contourSet the coordinates in the image
Some sample results:
roisfolder before running the code.Code: