I want to mirror an image in python but this error occur
Exception has occurred: IndexError
index -751 is out of bounds for axis 1 with size 750
File "D:\PART 1\Miror.py", line 20, in <module>
d=img.item(i,mn,0)
this is my code
img = cv2.imread('D:\\PART 1\\gwk.jpg')
tinggi = img.shape[0]
lebar = img.shape[1]
brightness = 100
nm=int(tinggi-1)
mn=int(lebar-1)
lebarBaru= int(lebar/2)
tinggiBaru= int(tinggi/2)
for i in np.arange(tinggiBaru):
for j in np.arange(lebarBaru):
a=img.item(i,j,0)
b=img.item(i,j,1)
c=img.item(i,j,2)
d=img.item(i,mn,0)
e=img.item(i,mn,1)
f=img.item(i,mn,2)
img.itemset((i,j,0),d)
img.itemset((i,j,1),e)
img.itemset((i,j,2),f)
img.itemset((i,mn,0),a)
img.itemset((i,mn,1),b)
img.itemset((i,mn,2),c)
mn-=1
I want to mirror an image in python without using OpenCV function for mirroring an image
Just invert the direction of one (or both if you like) dimensions of the image array.
Example with imageio, but should work the same with similar image arrays, too, like e.g. in opencv:
import matplotlib.pyplot as plt
import imageio
im = imageio.imread('imageio:chelsea.png')
fig, axs = plt.subplots(1, 3, sharey=True)
axs[0].imshow(im)
axs[1].imshow(im[:, ::-1, :])
axs[2].imshow(im[::-1, :, :])

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With