-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
Image Thresholding #1840
Comments
Hello @imgifty, Sure, you can do something like: image = pyvips.Image.new_from_file("huge.png", access="sequential")
image = image > 200
image.write_to_file("huge2.png") That will make a boolean image with 255 for TRUE (pixel was >200) and 0 for FALSE (pixel was <=200). If you save with PNG is a very slow file format. You could try using TIFF instead with You could also try a different zip library. zlib-ng is supped to be the fastest, I think. |
You can do more complex thresholding too, eg.: image = (image > 200).ifthenelse(200, image) Will make a bool image with the test, then set TRUE pixels to 200 and FALSE pixels back to the image again. image = (image.gaussblur(5) < image).ifthenelse([255, 0, 0], [0, 255, 0]) Will set pixels greater then the local average red, and pixels less than the local average green. |
Hello, The thresholding has worked perfectly. Thanks a lot! |
You probably have an old version of libvips -- PNG 1 bit save was added in 8.10. Yes, the threshold will be done on the three bands separately. If you want mono output, use something like: image = image.colourspace('b-w') > 200 ie. convert to mono before thresholding. |
Yes, that seems to be the case, as I'm working with libvips 8.4.5 . |
Sure, take the average and multiply by the number of pixels. |
This might be helpful. Did I do this right @jcupitt? Am I doing anything silly? https://gist.github.com/angstyloop/37d4454442beea452b718bb11469f2a4 |
I would write that C example as: libvips/ruby-vips#243 (comment) |
Thanks for responding to the same question twice @jcupitt I wasn't looking for the right terms when I was searching through the docs. It's really easy now that you've pointed me at those simple relational operations and provided that example. |
Here's where this ended up. I made a little GTK 3 app that uses the update_image function @jcupitt helped me write. Thanks again! Yay VIPS! https://gist.github.com/angstyloop/9e8d808570eab3329471e67b71e01f41 |
That's very cool! Did you see vipsdisp? https://github.com/jcupitt/vipsdisp It's a gtk4 image viewer using libvips. The image is computed with libvips, but rendered to the display using your GPU, so you can pan and zoom at 60fps (hopefully). It has scale and offset sliders (right click, enable the display control bar) which work a little like yours. The image display is done by tilesource.c, tilecache.c and imagedisplay.c -- it's a widget, so it should be simple to reuse in other applications. |
No sir I did not - that's very cool I'll have to dig into https://github.com/libvips/vipsdisp-tiny soon If it's not exactly 300 lines I want my money back |
vipsdisp-tiny is gtk3, but gtk4 is quite a bit different and trickier :( I think something like the vipsdisp image display system is probably the way to do. vipsdisp-tiny is still interesting to look at though. |
Fair enough - I built vipsdisp from source on Ubuntu 22.04. I used my
package manager's version of gtk 4, instead of building it from source with
meson/ninja. I'll build gtk 4 from source instead later.
…On Tue, Mar 7, 2023 at 1:42 AM John Cupitt ***@***.***> wrote:
vipsdisp-tiny is gtk3, but gtk4 is quite a bit different and trickier :( I
think something like the vipsdisp image display system is probably the way
to do.
vipsdisp-tiny is still interesting to look at though.
—
Reply to this email directly, view it on GitHub
<#1840 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIKRJAX7PVZMLMHF2X5QLV3W237H7ANCNFSM4R62WIRA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think the gtk4 in 22.04 is recent enough, you should be OK with that. Did it work? Try pressing "d" to get the debug display mode where you can see tiles being swapped in and out, it's cute! Hold down "i" for a smooth zoom in on the mouse pointer, "o" for a smooth zoom out. It should be fast even with very large images. Shift cursor left and right should do a smooth and fast screen sized pan. The info bar is updated in the main GUI thread, unfortunately, so you'll see a bit of hitching unless you turn that off. |
Hello,
I'm working on gigantic '.png' files with dimensions of 100'000x180'000 pixels, which I'd like to process. I would like to threshold the image according to a pixels color value. Is there a better way at doing this, than converting the image to a numpy array and doing the thresholding logic and converting it back into vips format?
The numpy conversion is taking an insane amount of time and memory and I would rather do it only in pyvips.
Is there any other way, I could speed up the whole process by converting all images into a pyramidic file format?
Thanks a lot for the answer and also for the great tool!
The text was updated successfully, but these errors were encountered: