Reputation: 52
any body can help identify the problem here?
i have the code here to concatenate H and L to present an image and whenever i run the code i get :
np.concatenate((H,L))
>> ValueError: zero-dimensional arrays cannot be concatenated
but i don't know why H and L are zero dimensional .thanks in advance
import cv2
import cv
import numpy as np
c1=0.5
c2=0.25
img1=cv2.imread("Penguin-cartoon.png") ## Genuine Image
img=cv2.imread("Penguin-cartoon.png",cv2.CV_LOAD_IMAGE_GRAYSCALE) #gray_scaled Image
A=img.astype(np.int16)
D=[]
C=[]
x,y=img.shape
B = np.empty((x,y), dtype = np.int16)
for j in range(1,y):
for i in range (0,x/2 -1 ):
if i==0:
P=A[j,2*i+2]*c1
B[j,2*i+1]=A[j,2*i+1]-P
elif i==x/2:
U=B[j,2*i-1]*c2
B[j,2*i]=A[j,2*i]+U
else :
P=(A[j,2*i-1]+A[j,2*i+2])*c1
B[j,2*i+1]=A[j,2*i+1]-P
U=(B[j,2*i-1]+B[j,2*i+1])*c2
B[j,2*i]=A[j,2*i]+U
for j in range(1,y):
for i in range (0,x/2 -1 ):
D=B[j,2*i-1]
C=B[j,2*i]
H=D.astype(np.uint8)
L=C.astype(np.uint8)
np.concatenate((H,L))
Upvotes: 1
Views: 654
Reputation: 11199
The objects H
, L
you are concatenating are scalars not arrays, hence the error. Their assignment in the last for
loop does not make sens,
for j in range(1,y):
for i in range (0,x/2 -1 ):
D=B[j,2*i-1]
C=B[j,2*i]
H=D.astype(np.uint8)
L=C.astype(np.uint8)
BTW, you should check some tutorials on the use of numpy. The idea is that in most cases, you can use vectorized numpy operations instead of iterating over the pixels of your array in Python. The former is much faster.
Upvotes: 1