I have a float32 signed image that displays when I use imshow() but gives a black output when using imwrite(), which I suspect is because the float 32 array has values between around -6 to 6, which result in the output having pixel values 6 in the 0-255 range.
I tried MINMAX normalisation, but this results in the black parts of the image flashing white when I iterate through the frames.
The float32 array I’m getting is the Brox optical flow output which I’d like to save as it is displayed in imshow().
How do I normalize these optical flow arrays to save them as .jpg or any other format that is small in size?
I’ve tried TIFF to get accurate outputs at the cost of size, but the outputs are still distorted.
Code:
#FLOW COMPUTATION
gpu_flow = brox_of.calc(gpu_prev, gpu_frame, None) #2 vectors
#splitting flow into 2
gpu_flow_x = cv2.cuda_GpuMat(gpu_flow.size(), cv2.CV_32FC1)
gpu_flow_y = cv2.cuda_GpuMat(gpu_flow.size(), cv2.CV_32FC1)
temp = cv2.cuda_GpuMat(gpu_flow.size(), cv2.CV_8U)
cv2.cuda.split(gpu_flow, [gpu_flow_x, gpu_flow_y], cv2.cuda.Stream_Null())
# set value to normalized magnitude from 0 to 255
#gpu_flow_x = cv2.cuda.normalize(gpu_flow_x, 0, 1, cv2.NORM_MINMAX, -1)
#print(gpu_flow_x.type())
#gpu_flow_y = cv2.cuda.normalize(gpu_flow_y, 0, 255, cv2.NORM_MINMAX, -1)
#help(cv2.cuda_GpuMat.convertTo)
gpu_flow_x.convertTo(cv2.CV_8U, temp)
x = gpu_flow_x.download()
y = gpu_flow_y.download()
#x3d = np.expand_dims(x, axis=2)
#x = x.astype(np.uint8)
cv2.imshow('temp', x)
The code looks bad now, but this is to show what functions I’ve tried using.