Ask Your Question
1

normalization not working

asked 2020-08-22 05:41:22 -0600

opencvstudent gravatar image

updated 2020-08-22 16:52:16 -0600

i'm trying to normalize an image. it isn't working. the pixel values are staying the same. help?

img = cv2.imread('image.jpg', 0)
norm_img = np.zeros((800,800))
final_img = cv2.normalize(img, norm_img, 0, 255, cv2.NORM_MINMAX)

the pixel values of img and final_img are unchanged. why?!

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-08-22 06:57:44 -0600

supra56 gravatar image

updated 2020-08-22 06:58:13 -0600

Drop zero:

img = cv.imread('image.jpg')
norm_img = np.zeros((800, 800))
final_img = cv.normalize(img,  normalizedImg, 0, 255, cv.NORM_MINMAX)
cv.imshow('final_img', final_img)
cv.waitKey(0)
cv.destroyAllWindows()

Or to use cv2.resize()

import cv2 as cv

img = cv.imread(('image.jpg')
img = cv.resize(img, (800, 800))
cv.normalize(img, img, 0, 255, cv.NORM_MINMAX)

cv.imshow('dst_rt', img)
cv.waitKey(0)
cv.destroyAllWindows()
edit flag offensive delete link more

Comments

thank you for the response. however, this doesn't work. my values are still unchanged. i tried both ways.

opencvstudent gravatar imageopencvstudent ( 2020-08-22 07:15:29 -0600 )edit

R u attempting roi?

supra56 gravatar imagesupra56 ( 2020-08-22 07:18:21 -0600 )edit

What happen if u attempt this final_img = cv2.normalize(img,None)? Or:

final_img =cv2.normalize(img, dst=None, alpha=0, beta=1,
                           norm_type=cv2.NORM_MINMAX, dtype=-1)
supra56 gravatar imagesupra56 ( 2020-08-22 07:22:02 -0600 )edit
1

no. i'm simply trying to normalize an image. but, it's not changing pixel values.

opencvstudent gravatar imageopencvstudent ( 2020-08-22 07:23:11 -0600 )edit
1

i tried 'None' as well. nothing happens.

opencvstudent gravatar imageopencvstudent ( 2020-08-22 07:23:35 -0600 )edit

i'm printing a matrix to look at the values - - they are unchanged from original to normalized

opencvstudent gravatar imageopencvstudent ( 2020-08-22 07:24:40 -0600 )edit
1

that does change the values, but it creates a blank image

opencvstudent gravatar imageopencvstudent ( 2020-08-22 07:36:52 -0600 )edit
1

The image is 8-bits so values should already be 0-255, right? The operation won't change pixel values.

Der Luftmensch gravatar imageDer Luftmensch ( 2020-08-22 08:18:50 -0600 )edit

What if u add channel?

norm_img = np.zeros((800, 800,3), np.uint8)
supra56 gravatar imagesupra56 ( 2020-08-22 08:30:15 -0600 )edit

Try adding this astype():

img = cv.resize(img, (800, 800)).astype(sp.uint8)
final_img = cv.normalize(img,  None, 0, 255, cv2.NORM_MINMAX)
supra56 gravatar imagesupra56 ( 2020-08-22 08:45:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-08-22 05:41:22 -0600

Seen: 2,491 times

Last updated: Aug 22 '20