Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

How to extract the 9 images from following image without text?

This image is DNA sequence visualization

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do this using ImageMagick which is installed on most Linux distros and is available for macOS and Windows.

It can be done at the command-line in Terminal. So, first we want to identify the areas that are images and reject the text. The easiest thing is to make all saturated colours white and all grey/unsaturated colours black:

convert dna.png -fx "saturation<0.5? 0 : 1" z.jpg

enter image description here

Now we can do "Blob Analysis" or "Connected Component Analysis" to find the white "blobs" like this:

convert dna.png -fx "saturation<0.5? 0 : 1"       
    -define connected-components:verbose=true     
    -connected-components 8 -auto-level output.png

Sample Output

Objects (id: bounding-box centroid area mean-color):
  0: 314x112+0+0 155.2,56.1 28249 srgba(0,0,0,2.31991)
  3: 100x16+214+23 262.9,30.4 1576 srgba(255,255,255,42.5831)
  2: 100x16+108+23 157.1,30.1 1511 srgba(255,255,255,44.3719)
  9: 100x8+2+88 50.4,91.4 777 srgba(255,255,255,85.3436)       <--- THIS ONE
  6: 100x7+2+55 50.7,57.9 687 srgba(255,255,255,96.393)
  1: 100x6+2+23 50.5,25.4 587 srgba(255,255,255,112.644)
  10: 100x6+108+96 156.9,98.0 507 srgba(255,255,255,130.26)
  7: 100x5+108+65 155.6,66.9 477 srgba(255,255,255,138.39)
  8: 100x5+214+65 263.3,66.5 399 srgba(255,255,255,165.248)
  11: 100x5+214+96 263.2,97.5 396 srgba(255,255,255,166.492)
  5: 1x1+110+33 110.0,33.0 1 srgba(0,0,0,65535)
  4: 1x1+200+27 200.0,27.0 1 srgba(0,0,0,65535)

There is a heading/title line then one line for each blob found in the image. Let's look at the line:

 9: 100x8+2+88 50.4,91.4 777 srgba(255,255,255,85.3436) 

That means there is a blob 100x8 pixels in size at offset (2,88) from the top-left corner. Let's fill it in semi-transparent red:

 convert dna.png -stroke red -fill "rgba(255,0,0,0.5)" -draw "rectangle 2,88 102,96" p.png

enter image description here

And let's crop it out into a new image:

convert dna.png -crop 100x8+2+88 +repage result.png

enter image description here

A little awk script will get the other blobs for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...