Assigning new colour component to an existent image
I was trying to apply an histogram processing only in the H component of HSV colour space, but the assignment of the result to the specified component image_hsv[0] is producing an error for the image object.
import pyvips
image = pyvips.Image.new_from_file('image.jpg', access='sequential')
image_hsv= image.colourspace("hsv")
result = image_hsv[0].hist_local(40, 40, max_slope=5)
image_hsv[0] = result
TypeError: 'Image' object does not support item assignment
Any idea of how to performe an operation in only one component and reassign it to the original image? Thank you
Hello @anaidasdfg,
libvips doesn't have destructive assignment -- you can only make new images, you can't update existing images.
Instead, you need to take the SV channels and attach the new H, so for example:
hsv = image.colourspace("hsv")
new_h = hsv[0].hist_local(40, 40, max_slope=5)
hsv = new_h.bandjoin(hsv[1:3])
You could also consider using LCh rather than HSV. LCh is quite a bit more accurate, though of course that may not be important in your application.
https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_model