Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do i autosize an image so that i do not get IndexError: index 303 is out of bounds for axis 0 with size 303

Whenever i'm trying to run the program i have made i get the indexError:

IndexError: index 303 is out of bounds for axis 0 with size 303

i can fix it and go into my np.zeros((rows,cols),3),np.uint8) and increas the values of the rows or cols to make the image fit, when tranformed. But is there any easier way to no do that an make a autosize function or something i've tried with namedWindow, but no luck so far

How do i autosize an image so that i do not get IndexError: index 303 is out of bounds for axis 0 with size 303

Whenever i'm trying to run the program i have made i get the indexError:

IndexError: index 303 is out of bounds for axis 0 with size 303

i can fix it and go into my np.zeros((rows,cols),3),np.uint8) and increas the values of the rows or cols to make the image fit, when tranformed. But is there any easier way to no do that an make a autosize function or something i've tried with namedWindow, but no luck so far far.

https://pastebin.com/JKWvuTTK

How do i autosize an image so that i do not get IndexError: index 303 is out of bounds for axis 0 with size 303

Whenever i'm trying to run the program i have made i get the indexError:

IndexError: index 303 is out of bounds for axis 0 with size 303

i can fix it and go into my np.zeros((rows,cols),3),np.uint8) and increas the values of the rows or cols to make the image fit, when tranformed. But is there any easier way to no do that an make a autosize function or something i've tried with namedWindow, but no luck so far.

My code: https://pastebin.com/JKWvuTTK

click to hide/show revision 4
None

updated 2018-10-28 09:44:12 -0600

berak gravatar image

How do i autosize an image so that i do not get IndexError: index 303 is out of bounds for axis 0 with size 303

Whenever i'm trying to run the program i have made i get the indexError:

IndexError: index 303 is out of bounds for axis 0 with size 303

i can fix it and go into my np.zeros((rows,cols),3),np.uint8) and increas the values of the rows or cols to make the image fit, when tranformed. But is there any easier way to no do that an make a autosize function or something i've tried with namedWindow, but no luck so far.

My code: https://pastebin.com/JKWvuTTK

# Important imports
import cv2
import numpy as np

# read image
img = cv2.imread("Mig.png", 0)
# image rows and columns
rows = img.shape[0]
cols = img.shape[1]
# Copys of image for shearing
imgCopy1 = np.zeros((rows+266, cols, 3), np.uint8)
imgCopy2 = np.zeros((rows+266, cols, 3), np.uint8)
imgCopy3 = np.zeros((rows, cols, 3), np.uint8)
imgCopy4 = np.zeros((rows, cols, 3), np.uint8)
# Shear factors
Bx = 1
By = 1

for i in range(0, rows):
    for j in range(0, cols):
        yOffSet = By * j
        k = img[i, j]
        imgCopy1[i + yOffSet, j] = k
for i in range(0,rows):
    for j in range(0,cols):
        yOffSet = By * j
        k = img[i,j]
        imgCopy2[i - yOffSet + cols,j] = k




cv2.imshow("normal", img)
cv2.imshow("shear", imgCopy1)
cv2.imshow("shear1", imgCopy2)
cv2.imwrite("sheardImg.png",imgCopy1)
cv2.waitKey()
cv2.destroyAllWindows()