3

I'm aware of the solution to a similar problem by Hayashi Yoshiaki. Is there a way of extending the solution to break out the chromosomes from this example I have a mass of data in this format that needs to be converted to a training set. Note the there are holes in the chromosome that the human ignores when segmenting. Doing this manually for hundreds of images is a challenge. Thanks in advance

Example subset of images of chromosome

C. E.
  • 70,533
  • 6
  • 140
  • 264
Boris
  • 421
  • 2
  • 6
  • Please give a link to Yoshiaki's solution. – C. E. Jul 31 '17 at 17:30
  • https://mathematica.stackexchange.com/questions/109154/can-i-split-an-image-into-subparts-automatically/109157#109157 – Boris Jul 31 '17 at 17:47
  • Are all your images aligned and roughly equally spaced like this one? – yohbs Jul 31 '17 at 18:55
  • Yes, thats right. They are autogenerated. some are long and bent but all are essentially equidistant. – Boris Jul 31 '17 at 19:00
  • This image looks pretty easy to divide, to the extent that a very straightforward algorithm can be written (basically - detecting columns that are almost totally white). It would be helpful if you could provide a few more samples so that we can check the robustness. – yohbs Jul 31 '17 at 19:14
  • @Boris, you say that these images are autogenerated. If so then, could you have each chromosome take exactly the same horizontal space? Then you would just need ImagePartitions[image, Scaled[{1/17,1}]. At this time, that approach doesn't work because the widths are different for different chromosomes unfortunately. – MarcoB Jul 31 '17 at 19:14

1 Answers1

1

Here's the very straightforward method I suggested in my comment:

tot = Total@ImageData[Binarize[im, 0.9]];
columnsSequence = Flatten@Position[tot, x_ /; x >= 103];
columns = Round@(Mean /@ Split[columnsSequence, #2 - #1 == 1 &]);
imd = ImageData[im];
imd[[All, columns, All]] = 0;
Image[imd]

This is just drawing the lines that separate the chromosomes. From here you can split the image or do any other further manipulation. For calculating the best separating "white column" I used this trick.

enter image description here

Here's how to divide the image to subimages:

imd=ImageData[ims]
images = Table[
  imd[[All, columns[[i]] ;; columns[[i + 1]], All]], {i, 
   Length[columns] - 1}]
Image /@ images

enter image description here

yohbs
  • 7,046
  • 3
  • 29
  • 60
  • OK, its a good start - how do I generate a list of images from this? I'll post a page of data from one example in the morning. – Boris Jul 31 '17 at 22:31
  • Hi yohbs, Ive tested your routine on other sets and find that I need to adjust the position parameter but thats OK I can automate that. Im having trouble breaking out the individual components due to my limited familiarity with array handling. I shall persevere. – Boris Aug 01 '17 at 10:28
  • this seems to work- not elegant Im afraid: – Boris Aug 01 '17 at 13:59
  • pt1 = Drop[Partition[Riffle[columns, 0], 2], -1]; pt2 = Drop[Partition[Riffle[columns, 116], 2], 1]; components = Partition[Partition[Flatten[Transpose[{pt1, pt2}]], 2], 2]; images = ImageTrim[im, #] & /@ components – Boris Aug 01 '17 at 14:00
  • @Boris You can do it more cleanly. I'll edit my answer. – yohbs Aug 01 '17 at 14:04
  • @ yohbs just seen your edit - worth the wait. – Boris Aug 01 '17 at 21:01