Closed Tychology closed 5 months ago
Hello! Image:set
only sets image metadata, i.e. what colourspace the image is in right now. To convert an image to a different interpretation, you'll want to look at Image:colourspace
.
I know, I only want to set the image metadata, not invoke a colourspace conversion, just treat the data differently. Since I basically want to assemble an hsv from parts and tell vips to actually treat it it as hsv. the problem is that calling Image:set
doesn't set the interpretation metadata for some reason. I checked with a debugger and Image:get
. the interpretation field is just not changed after Image:set
.
Hiya, copy()
is the best thing to use for this, eg.:
img = img:copy{interpretation = "srgb"}
Behind the scenes it's just a pointer copy, so this is very fast.
libvips is (almost) all immutable, so you make new objects, you don't modify existing objects.
You can use set()
, but you have to be very careful, since pointers can be shared through the system by the various caches and you might be modifying an image some other part of your program is using. You need to make sure you have a private and unique image first with copy()
.
I think set()
also won't set the builtin header fields like width
and interpretation
, since it's so easy to trigger a hard crash. copy()
lets you set these things, but applies a set of sanity checks which prevent you changing the size of pixels, or addressing out of range memory.
The ruby binding has a feature for this:
https://www.libvips.org/2021/03/08/ruby-vips-mutate.html
The mutate
block lets you create an image which can be modified safely. It'd be neat if lua-vips could have something similar, though I suppose the syntax wouldn't be so nice.
Thank you very much, it worked!
If set() doesn't work on certain field I think It would be a good idea to have that documented or at least not fail silently but with a warning or even an error.
Haha, your parrots look great!
I tried to improve the docs for set
and remove
.
This is off-topic, but LCh is a better colourspace than HSV, it might be worth trying that. It's perceptually uniform, so hue changes ought to match angle changes in a more obvious way.
I'm closing the issue, since the docs update has been merged into master.
I want to calculate the magnitude and angle of the gradient of an image and display the magnitude as the value and the angle as the hue of HSV. But because
set("interpretation", "multiband")
andset("interpretation", "hsv")
doesn't seem to do anything, when I load an srgb image I get an image back that is still incorrectly interpreted as srgb bywrite_to_file
I really don't understand why
set("interpretation",
does't work. Trying to set using an invalid enum value gives this error message which indicates that this is the correct way of setting the interpretation attribute of an image object:lua: /usr/local/share/lua/5.4/vips/gvalue.lua:76: no such enum invalid lua-vips: enum 'VipsInterpretation' has no member 'invalid', should be one of: error, multiband, b-w, histogram, xyz, lab, cmyk, labq, rgb, cmc, lch, labs, srgb, yxy, fourier, rgb16, grey16, matrix, scrgb, hsv
Here is my input and output:
![grad](https://github.com/libvips/lua-vips/assets/38350366/fa00e59b-f6b9-4b61-b20f-cf515f7b058a)