I have two huge tables with 7241 and 1469620 rows (700KB, 141MB)

listData = 
  Import["https://www.dropbox.com/s/s2p7sozkjt67tii/listdata.csv?dl=1", "CSV"];

whitepositions = 
  Import["https://www.dropbox.com/s/03qkfszuvq0qbut/whitepositions.csv?dl=1", "CSV"];

I have a Do loop and it takes a long time for running.

dl = DelaunayMesh[listData];
cells = MeshCells[dl, 2];
cellcoord = Map[MeshCoordinates[dl][[#]] &, cells, {2}];

Do[{mf[i] = RegionMember[cellcoord[[i]]];
tf[i] = mf[i][whitepositions];
tf[i] = Length[Cases[tf[i], True]]}, {i, 1, Length[cellcoord]}]

listData is a data stream of many seed points to generate a Delaunay mesh.

whitepositions is the white pixel coordinates from a binary image.

Is there any way to boost the efficiency?

Thank you!

  • $\begingroup$ It would be easier for us to help if you described what it is that you're trying to achieve with the code. It seems like you're trying to count how many white pixels are in each cell, is that right? $\endgroup$
    – yohbs
    May 19, 2017 at 13:25
  • $\begingroup$ Yes, I want to count how many white pixels in every single Delaunay triangle. $\endgroup$
    – Shuoqi Li
    May 20, 2017 at 5:04
  • 1
    $\begingroup$ Quick and dirty method: Find the triangle with the closest center using Nearest and test only that one. If the test point is inside, you can skip testing all the other triangles. If it's not inside (hopefully rare), test all of them. $\endgroup$ May 20, 2017 at 9:26
  • $\begingroup$ As it is now, it takes two seconds per iteration, for 14455 steps that is more than 8 hours. @nikie can you provide an efficient implementation for your idea? $\endgroup$
    – rhermans
    May 22, 2017 at 10:19
  • 1
    $\begingroup$ @rhermans: To be honest, I won't bother for a question that has almost no value for anyone but the OP. This isn't a free coding service ;-) $\endgroup$ May 22, 2017 at 17:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.