I have a dataset which has spatial objects (the red blobs in the picture below) that cover a number pixels or grid points - but has irregular shapes. I have another dataset which consists of points with 2D coordinates and I want to know whether each point in this dataset is within a certain distance from any pixel of any of the spatial objects. The main problem I have is that I have to explicitly look into each object struct to find its location and pixels. Is there a way for me to index the spatial information of the data such that I can perform this search more efficiently? Right now, I am doing it brute force, where given a point from the second dataset I have to loop through each object, check its location, check the location of its pixels, and then test if any one pixel is within a distance X from the point. I am using MATLAB but if there are any packages I could use in any language that would be great.
