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

  • $\begingroup$ Please give a link to Yoshiaki's solution. $\endgroup$ – C. E. Jul 31 '17 at 17:30
  • $\begingroup$ mathematica.stackexchange.com/questions/109154/… $\endgroup$ – Boris Jul 31 '17 at 17:47
  • $\begingroup$ Are all your images aligned and roughly equally spaced like this one? $\endgroup$ – yohbs Jul 31 '17 at 18:55
  • $\begingroup$ Yes, thats right. They are autogenerated. some are long and bent but all are essentially equidistant. $\endgroup$ – Boris Jul 31 '17 at 19:00
  • $\begingroup$ 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. $\endgroup$ – yohbs Jul 31 '17 at 19:14

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;

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:

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

enter image description here

  • $\begingroup$ 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. $\endgroup$ – Boris Jul 31 '17 at 22:31
  • $\begingroup$ 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. $\endgroup$ – Boris Aug 1 '17 at 10:28
  • $\begingroup$ this seems to work- not elegant Im afraid: $\endgroup$ – Boris Aug 1 '17 at 13:59
  • $\begingroup$ 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 $\endgroup$ – Boris Aug 1 '17 at 14:00
  • $\begingroup$ @Boris You can do it more cleanly. I'll edit my answer. $\endgroup$ – yohbs Aug 1 '17 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.