Opencv + Python cv2.imwrite() and cv.imshow both images present different output -
i using opencv(3.0) , python 2.7 image processing, have issue cv2.imwrite()
, cv2.imshow()
. produce different output, code below:
tfinal = (255)*(nir_img-red_img)/(nir_img+red_img) cv2.imwrite(_db_img1+'_ndvi'+_ext_img,tfinal) cv2.imshow('ndvi',tfinal)
first image output of cv2.imshow()
second image output of cv2.imwrite()
this can happen because of data type. imwrite
, imshow
determine data automatically, relaying on datatype. said in documentation imwrite , imshow:
imwrite
:
the function imwrite saves image specified file. image format chosen based on filename extension (see imread() list of extensions). 8-bit (or 16-bit unsigned (cv_16u) in case of png, jpeg 2000, , tiff) single-channel or 3-channel (with ‘bgr’ channel order) images can saved using function.
imshow
:
the function may scale image, depending on depth:
- if image 8-bit unsigned, displayed is.
- if image 16-bit unsigned or 32-bit integer, pixels divided 256. is, value range [0,255*256] mapped [0,255].
- if image 32-bit floating-point, pixel values multiplied
- that is, value range [0,1] mapped [0,255].
so, seems underlying data type not unsigned char, float or 32-bit integer.
also because of operation priorities can run troubles with:
(255)*(nir_img-red_img)/(nir_img+red_img)
you can run overflow. better set values in range of [0; 1] , multiply them:
(255) * ( (nir_img-red_img)/(nir_img+red_img) )
Comments
Post a Comment