sinB
sinB

Reputation: 185

Removing single pixel row from image in Python 3 with PIL

Is there any simple way to remove a single row of pixels in PIL (Pillow)?

removing pixel row

I have considered

But it seems unnecessary complicated.

I am not familiar with modifying images in other python libraries, but if it is significantly simplyfying the task I will consider it.

Upvotes: 1

Views: 2375

Answers (1)

duckboycool
duckboycool

Reputation: 2455

You could convert the image into a numpy array using numpy.array(image) and then use numpy.delete() to remove a row before converting it back into an image with PIL.Image.fromarray().

For example, this would remove the 7th row from the image.

a = numpy.array(im)

a = numpy.delete(a, 6, 0)

im = Image.fromarray(a)

Upvotes: 3

Related Questions