How to assign image components in pyvips?

331 views Asked by At

I am using the pyvips library which has a special object for images, these objects have the 3 bands corresponding to HSV (or other) colour space components. The problem is that, after filtering one of the HSV components, it is not allowed to assign it again to the ogirinal image. On this code you can see what is written and the error.

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

I also tried assigning directly a numpy array to the image_hsv[0] but neither worked.

Library doc: documentation here https://libvips.github.io/pyvips/

Image object doc: https://libvips.github.io/pyvips/vimage.html

1

There are 1 answers

0
asdfg On BEST ANSWER

It worked for me finally by avoiding the auxiliary variables.

image = pyvips.Image.new_from_file('image.jpg', access='sequential')
image_hsv= image.colourspace("hsv")
image_hsv[0].hist_local(40, 40, max_slope=5)