# Improve efficiency of RegionMember with huge number of points

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!

• 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? May 19, 2017 at 13:25
• Yes, I want to count how many white pixels in every single Delaunay triangle. May 20, 2017 at 5:04
• 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. May 20, 2017 at 9:26
• 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? May 22, 2017 at 10:19
• @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 ;-) May 22, 2017 at 17:39