-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute mask and sample from it #264
Comments
Hi @gabrieldernbach, It should be easy, yes. Could you give some more detail? Do you mean you want a histogram of pixels within a mask? Or do you want to sample random points within a masked area? |
It is the latter, I want to sample random points within a masked area. I aim for an np.array of shape More context: |
I think you'd probably need to fetch every tile in the image, then mask it before passing it to your network or whatever you are using. You could generate the mask with pyvips I guess, something like (untested): image = ...
# a one-band uint8 image with 255 for areas which are white
mask = (image == 255).bandand()
# region fetch is usually faster than crop / write_to_memory, though it depends on the tile size
image_region = pyvips.Region.new(image)
mask_region = pyvips.Region.new(mask)
# fetch a 128x128 block of pixels from each ... you can wrap a numpy array around these
# pointers
image_bytes = image_region.fetch(100, 100, 128, 128)
mask_bytes = mask_region.fetch(100, 100, 128, 128) |
Discussion of |
I need to match the color distribution between some images using a custom algorithm. In order to estimate the distribution I would like to sample rgb values from the image. Typically there are very large white areas that I need to exclude first.
Can this be done with pyvips? If so can you tell me how?
The text was updated successfully, but these errors were encountered: