Skip to content

Instantly share code, notes, and snippets.

@maheshs11
Created August 3, 2022 17:09
Show Gist options
  • Save maheshs11/332ac21ed3bbcf8470f0f5fe7b80459e to your computer and use it in GitHub Desktop.
Save maheshs11/332ac21ed3bbcf8470f0f5fe7b80459e to your computer and use it in GitHub Desktop.
np.reshape
image = cv2.imread("/content/paper1.jpg")
_shape_1= image.shape
print("The shape of image is:",_shape_1)
print("The product shape of image is:", np.prod(_shape_1))
dim = np.prod(_shape_1)
num = dim
factors=[]
for i in range(1,num+1):
if num%i==0:
factors.append(i)
#print ("Factors of shape is {} = {}".format(num,factors))
test = []
for i in factors:
for j in factors:
for k in range(0,1000):
if i*j*k == num:
if i <= 3000 and j <= 5000 and k <=3: # set this values acc to required shape
test.append([i,j,k])
print("The possible values to reshape: ",test)
print("The size to be reshaped to:",tuple(test[0]))
moy = np.reshape(image,tuple(test[0]))
new_shape = moy.shape
print("The reshaped image size is: ",new_shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment