自动创作图像,然后从图像中提取感兴趣的区域
我想自动裁剪图像,这意味着我不想每次都指定像素或坐标,模块/代码应该检测对象(即感兴趣的区域)并从图像中提取它。
或者有任何算法从图像中裁剪所需的部分(感兴趣的区域) [例如,我的图像包含两部分,一部分是白色,另一部分是 RGB 形式,但我只想要完整图像中的 RGB 形式部分]。
我也尝试过下面的代码,但没有帮助。
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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论