pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

Parallel function like numpy.roll to slide image in sequential mode

Open akaprasanga opened this issue 6 years ago • 2 comments

I am trying to slide the image horizontally and vertically with certain pixels. For now, I am doing this by cropping the row or column of the original image and joining them together but doing so violates the sequential access mode. Numpy has an inbuilt function np.roll(image, shift_value, axis) and I am curious if there is any function like np.roll in pyvips.? Or is there any way around to accomplish the same task without violating sequential mode?

shifting_value = 200
img = pyvips.Image.new_from_file("A.jpg", access='random')
w, h = img.width, img.height

# sliding image upwards
lower_portion = img.crop(0, shifting_value, w, h - shifting_value)
upper_portion = img.crop(0, 0, w, shifting_value)
lower_portion = lower_portion.join(upper_portion, 'vertical')
#lower_portion.write_to_file("shifted_up.jpg")

#sliding image downwards
lower_portion = img.crop(0, h - shifting_value, w, shifting_value)
upper_portion = img.crop(0, 0, w, h - shifting_value)
lower_portion = lower_portion.join(upper_portion, 'vertical')
lower_portion.write_to_file("shifted_down.jpg")

akaprasanga avatar Jul 31 '19 03:07 akaprasanga

Hello, yes, wrap does this:

b = a.wrap(x=50, y=50)

Wraps the origin around to (50, 50).

It won't work in sequential mode, sorry. You'd need to copy to memory beforehand:

b = a.copy_memory().wrap(x=50, y=50)

jcupitt avatar Jul 31 '19 03:07 jcupitt

Thank you very much it helped a lot.

akaprasanga avatar Jul 31 '19 04:07 akaprasanga