如何从以下没有文本的图像中提取9张图像? [英] How to extract the 9 images from following image without text?

查看:63
本文介绍了如何从以下没有文本的图像中提取9张图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此图像是DNA序列可视化

推荐答案

如果您不喜欢命令行方法,我已在 Python 中重铸了我的 ImageMagick 答案.我是 Python 的初学者,因此我的代码可能效率低下,操作不当,但可以使用.该技术与其他答案完全相同:

In case you don't like the command-line approach, I have recast my ImageMagick answer in Python. I am quite a beginner in Python so there may be inefficiencies and poor practices in my code, but it works. The technique is exactly the same as the other answer:

  • 转换为HSV色彩空间,并找到高度饱和(彩色)的像素,
  • skimage 运行label()进行连接的组件" 标记,
  • 提取blob并另存为文件.
  • convert to HSV colourspace, and locate highly saturated (coloured) pixels,
  • run label() from skimage to do "Connected Component" labelling,
  • extract blobs and save as files.
#!/usr/local/bin/python3

import numpy as np
from PIL import Image
from skimage import color
from skimage.measure import label, regionprops

# Load image and convert to RGB discarding any alpha
im=np.array(Image.open('dna.png').convert('RGB'))

# Add 1px black border all around so shapes don't touch edges
blackcanvas=np.zeros((im.shape[0]+2,im.shape[1]+2,3))
blackcanvas[1:-1,1:-1]=im
im=blackcanvas

# Convert to HSV colourspace, discard H, V and find saturated (i.e. brightly coloured) pixels
HSV=color.rgb2hsv(im)
S=HSV[:,:,1]
bw=(S>0.5)*255

# Image is now white blobs on black background, so label() it
label_image=label(bw)

# Iterate through blobs, saving each to disk
i=0
for region in regionprops(label_image):
   if region.area >= 100:
      # Extract rectangle containing blob and save
      name="blob-" + str(i) + ".png"
      minr, minc, maxr, maxc = region.bbox
      Image.fromarray(im[minr:maxr,minc:maxc,:].astype(np.uint8)).save(name)
      i = i + 1

这篇关于如何从以下没有文本的图像中提取9张图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆