首页 > 编程知识 正文

python16进制转字符,python十进制转16进制

时间:2023-05-05 15:52:52 阅读:12843 作者:1166

I have an image with data type int16。

sowhenihavetoconvertitsrangeto0- 255,I got two ways to do that in Python。

1 ) use numpy.uint 8功能目录

2 ) useopencvcv2. tsdlqalizefunctionwith0- 255 rangeandthenusenumpy.uint 8。

In Matlab,wedirectlygettheconversionusinguint 8功能区。

In

Also in second case,iused norm _ minmaxandtherangeofintensityvaluesgetschangedto0- 4。

watisthecorrectwaytodotheconversion?

All of these do different things。

NP.uint8considersonlythelowestbyteofyournumber.it ' slikedoingvalue0x ff。

img=NP.Array([2000,- 150,11 ],dtype=np.int16 ) )。

是NP.uint8(img )

阵列([ 208,106,11 ],dtype=uint8) )。

cv2.tsdlqalizewiththecv2. norm _ minmaxtsdlqtypetsdlqalisesyourvaluesaccordingtothetsdlqalisationfunction

img_new=(img- img.min () ) jkdcc ) _new-min_new )/(img.max )-img.min () ) ) min_new

iteffectivelychangesonerangetoanotherandallthevaluesinthebetweenarescaledaccordingly.bydefinitiontheoriginalmin/maxvaluesbbbetion

cv2.tsdlqalize(img,out,0,255,cv2.NORM_MINMAX ) )。

array ([ 255,0,19 ],dtype=int16 )。

uint8inmatlabsimplysaturatesyourvalues.everything above 255 becomes 255 andeverythingbelow0becomes 0。

uint8([2000-15011]

255 0 11

ifyouwanttoreplicatematlab ' sfunctionality,you can do

img[img 255]=255

img[img 0]=0

whichoneyouwanttousedependsonwhatyou ' retrying todo.if your int 16 coverstherangeofyourpixelvaluesandyouwanttorescalethosetouint

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。