-
Notifications
You must be signed in to change notification settings - Fork 36
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
Segmentation fault with dilate #125
Comments
A segmentation fault isn't good - I will put together a minimal case using your example and report to @akash-akya and the [vix](https://github.com/akash-akya/vix repo) since the underlying cause would seem to come from However, I've not seen a use case for a large dilation amount. Can you let me know what you're trying to achieve - perhaps there is another way? The implementation of In addition, I would expect the results to be visually quite unpleasant given the lack of anti-aliasing. There are some alternative implementations I can look at using libvips morphology which may - or may not - improve the situation. You might find the following discussions on the |
I recall now why the implementation uses a rank filter. It's because the rank filter can work on any non-complex image whereas the morphogical functions expect a binary (0 or 255) mask. So there may not be a "better" implementation. It's possible that using Vix.Vips.Operation.rank/4 with a larger window might help but I haven't tried that. The current implementation of |
I used an exaggerated value in the example for demonstration purposes. For the real use case, I'm using a value of 40 and it crashes with an image size of 512 x 512. Like you said, segmentation fault is irrecoverable either way. Please let me know if I can provide any more context. Thanks! |
Agreed that segmentation fault is a bug - I'll work on an upstream report on that. I'd be curious to see what you're working on if thats appropriate in the future. |
Appreciate it 🙏 You can check out the project that I'm working on here. |
Closing in favour of akash-akya/vix#144 (will reopen if required). |
Huge pipelines will crash with a C stack overflow. Repeating operations in a loop works well for immediate mode image processing systems, but it will perform very badly for demand-driven systems like libvips -- repeating an operation 500 times will make a pipeline 500 nodes long! It's best to find another way to solve the problem. For example, you can dilate the mask with a big radius, then use the dilated mask to dilate the image. You can also render each iteration to a new memory image. In python: for _ in range(500):
image = image.dilate(3).copy_memory() Now you are making 500 short pipelines and rendering each one to a big area of memory, in effect what systems like PIL or imagemagick do. You'll lose streaming and large image support, but pipeline length will be constrained. |
It crashes even with a value of 30 or 40 for some images, moreover, crashing the VM is irrecoverable; at least getting an exception thrown would be more graceful. |
It depends how large your C stack is, how much is used by your VM, and where the stack pointer is when you start evaluation. I tried in python: #!/usr/bin/env python
import sys
import pyvips
image = pyvips.Image.new_from_file(sys.argv[1])
for _ in range (int(sys.argv[2])):
image = 255 - image
data = image.write_to_memory() I see:
It's not something that libvips can really warn about or control, though vix might be able to. See eg. libvips/libvips#3832 (comment) |
Weirdly there's no |
I have refactored Breaking Changes
|
That sounds great!
You could probably raise that, I guess? |
Yes, it could be raised. I'm not sure if visually it's going to be good enough to accept for the library but I'll do some more tests. |
When I use dilate with higher pixel values (depending on the image), I get a segmentation fault and the whole Beam crashes:
I created a livebook to replicate the issue (uploaded as a zip file since GitHub doesn't support direct livemd file uploads):
dilate_seg_fault.zip
Input image:
The code simply extracts the alpha channel as a mask and applies
dilate
to it:It depends on the image, but for higher pixel values like
500
it definitely crashes.The text was updated successfully, but these errors were encountered: