1 year ago
#364624
Akshay Sable
Auto-crop the image, and extract the area of interest from image
I want to crop image automatically, it means I don't want to specify the pixels or coordinates each time, the module/code which should detect the object (i.e. area of interest) and extract it from an image.
Or there is any algorithm to crop desired part from image (Area of Interest) [for example my image contains two part one is white and other is in RGB form, but I want only the RGB form part from complete image].
I have also tried below code, but it was not helpful.
from PIL import Image
from skimage.io import imread
from skimage.morphology import convex_hull_image
im = imread('L_2d.jpg')
plt.imshow(im)
plt.title('input image')
plt.show()
# create a binary image
im1 = 1 - rgb2gray(im)
threshold = 0.5
im1[im1 <= threshold] = 0
im1[im1 > threshold] = 1
chull = convex_hull_image(im1)
plt.imshow(chull)
plt.title('convex hull in the binary image')
plt.show()
imageBox = Image.fromarray((chull*255).astype(np.uint8)).getbbox()
cropped = Image.fromarray(im).crop(imageBox)
cropped.save('L_2d_cropped.jpg')
plt.imshow(cropped)
plt.show()
python
opencv
image-processing
crop
yolo
0 Answers
Your Answer