本文整理汇总了Python中numpy.uint16函数的典型用法代码示例。如果您正苦于以下问题:Python uint16函数的具体用法?Python uint16怎么用?Python uint16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uint16函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mpl_Hough
def mpl_Hough(csv_head, img, gray, png_x, png_y, hot_r, png_ruler, lowThreshold, higThreshold):
min_Dist, sml_Radius, big_Radius = hot_R_Hough(hot_r, png_ruler)
circles1 = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT ,1,
minDist=min_Dist,param1=lowThreshold,param2=higThreshold,
minRadius=sml_Radius,maxRadius=big_Radius)
img0 = np.array(img)
w, h = gray.shape
line_x = np.uint16(round(png_x))
line_y = np.uint16(round(png_y))
cv2.line(img0,(line_x,0),(line_x,h),(255,0,0),2)
cv2.line(img0,(0,line_y),(w,line_y),(255,0,0),2)
if circles1 is None:
cv2.imshow('mpl_Hough',img0)
return 0,0,0,0
else:
circles = circles1[0,:,:]#三维提取为二维,非常易出Bug,返回值为NoneType或数组
png_x, png_y, png_r = select_Hot_Spot(circles,png_x,png_y)
circles = np.uint16(np.around(circles))#四舍五入,取整
for i in circles[:]:
cv2.circle(img0,(i[0],i[1]),i[2],(0,0,255),2)#画圆
cv2.circle(img0,(i[0],i[1]),2,(0,0,255),2)#画圆心
box_x0, box_y0, box_x1, box_y1 = lock_Box_Draw(png_x, png_y, png_r)
cv2.rectangle(img0,(box_x0,box_y0),(box_x1,box_y1),(0,255,0),2)
pzt_x, pzt_y = pngXY_to_pztXY(csv_head, gray, png_x, png_y)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img0,"({:.2f}, {:.2f})".format(pzt_x, pzt_y),(10,30), font, 0.8,(255,255,255),2)
cv2.imshow('mpl_Hough',img0)
return 1, png_x, png_y, png_r #浮点像素坐标值
示例2: get_bits
def get_bits(self, b):
nb = numpy.uint8(b) # bit8
#
num_word = numpy.uint32(self.cur_bit) # bit32
nbit_on_word = numpy.uint8(num_word - ((num_word >> 4) << 4)) # bit8
num_word = num_word >> 4
nbit_on_sword = numpy.uint8(0) # bit8
#
rtail = 16 - numpy.int8(nbit_on_word + nb)
if rtail < 0:
nbit_on_sword = numpy.uint8(abs(rtail))
rtail = 0
#
if num_word < len(self.out_buf):
left_p = numpy.uint16((self.out_buf[num_word] << nbit_on_word) >> (nbit_on_word + rtail)) # bit16
else:
left_p = numpy.uint16(0)
if (num_word + 1) < len(self.out_buf):
right_p = numpy.uint16(self.out_buf[num_word + 1] >> (16 - nbit_on_sword)) # bit16
else:
right_p = numpy.uint16(0)
#
left_p <<= nbit_on_sword
#
self.cur_bit += b
return left_p + right_p
示例3: save
def save(self, file_name):
'''
Save data to a binary file and flush output buffer
:param file_name:
'''
# Start of writing
try:
fid = open(file_name, 'wb')
except IOError:
print 'Can''t create file: {0}'.format(file_name)
return
# Write options to binary file
fid.write('fc')
fid.write(numpy.uint8([1, 0]))
fid.write(numpy.uint16(self.option.width))
fid.write(numpy.uint16(self.option.height))
fid.write(numpy.uint16(self.option.rank_size))
fid.write(numpy.uint16(self.option.min_rank_size))
fid.write(numpy.uint8(self.option.dom_step))
# Write main data to binary file
data_ln = numpy.uint32(numpy.ceil(self.cur_bit / 8.0))
fid.write(data_ln)
fid.write(self.out_buf[: (data_ln / 2)])
# End of writing and clear output buffer
fid.close()
del self.out_buf
示例4: _combine_bytes
def _combine_bytes(msb, lsb):
msb = np.uint16(msb)
lsb = np.uint16(lsb)
value = (msb << 8) | lsb
return np.int16(value) / 900
示例5: save
def save(self, fname):
with open(fname, "w") as f:
np.uint16(self.location).tofile(f)
np.uint16(len(self.stack)).tofile(f)
np.array(self.stack, dtype=np.uint16).tofile(f)
self.register.tofile(f)
self.memory.tofile(f)
示例6: wire_value
def wire_value(token, solved_wires):
if str.isdigit(token):
return uint16(token)
elif token in solved_wires.keys():
return uint16(solved_wires.get(token))
else:
return None
示例7: identify
def identify(self):
# get the current byte at pc
rom_instruction = True
self.instruction_byte = self._get_memory_owner(self.pc_reg).get(self.pc_reg)
if type(self.instruction_byte) is not bytes:
rom_instruction = False
self.instruction_byte = bytes([self.instruction_byte])
# turn the byte into an Instruction
self.instruction = self.instructions.get(self.instruction_byte, None) # type: Instruction
if self.instruction is None:
raise Exception('Instruction not found: {}'.format(self.instruction_byte.hex()))
# get the data bytes
if rom_instruction:
self.data_bytes = self.rom.get(self.pc_reg + np.uint16(1), self.instruction.data_length)
else:
if self.instruction.data_length > 0:
self.data_bytes = bytes([self.get_memory(self.pc_reg + np.uint16(1), self.instruction.data_length)])
else:
self.data_bytes = bytes()
# print out diagnostic information
# example: C000 4C F5 C5 JMP $C5F5 A:00 X:00 Y:00 P:24 SP:FD CYC: 0
print('{}, {}, {}, A:{}, X:{}, Y:{}, P:{}, SP:{}'.format(hex(self.pc_reg),
(self.instruction_byte + self.data_bytes).hex(),
self.instruction.__name__, hex(self.a_reg),
hex(self.x_reg), hex(self.y_reg),
hex(self.status_reg.to_int()), hex(self.sp_reg)))
示例8: encode_color
def encode_color(grey_left, grey_right):
"""
encodes the two grey values from two corresponding pixels in
one color value.
grey_left, grey_right must be integer between 0 and 1023 or castable to it.
returns tuple of r,g,b as integer between 0 and 255.
>>> encode_color(0, 0)
(0, 0, 0)
>>> encode_color(1020, 0)
(0, 255, 0)
"""
# store most significant bits of grey_left in green
green = np.uint16(grey_left/4)
# store most significant bits of grey_right in red
red = np.uint16(grey_right/4)
# store least significant two bits in correct blue bits
# for left it has to be in the 5th and 6th bit
# for right it has to be in the 1st and 2nd bit
blue = np.uint16((grey_left % 4)*16 + (grey_right % 4)*1)
return( (green, red, blue) )
示例9: testIntMax
def testIntMax(self):
num = np.int(np.iinfo(np.int).max)
self.assertEqual(np.int(ujson.decode(ujson.encode(num))), num)
num = np.int8(np.iinfo(np.int8).max)
self.assertEqual(np.int8(ujson.decode(ujson.encode(num))), num)
num = np.int16(np.iinfo(np.int16).max)
self.assertEqual(np.int16(ujson.decode(ujson.encode(num))), num)
num = np.int32(np.iinfo(np.int32).max)
self.assertEqual(np.int32(ujson.decode(ujson.encode(num))), num)
num = np.uint8(np.iinfo(np.uint8).max)
self.assertEqual(np.uint8(ujson.decode(ujson.encode(num))), num)
num = np.uint16(np.iinfo(np.uint16).max)
self.assertEqual(np.uint16(ujson.decode(ujson.encode(num))), num)
num = np.uint32(np.iinfo(np.uint32).max)
self.assertEqual(np.uint32(ujson.decode(ujson.encode(num))), num)
if platform.architecture()[0] != '32bit':
num = np.int64(np.iinfo(np.int64).max)
self.assertEqual(np.int64(ujson.decode(ujson.encode(num))), num)
# uint64 max will always overflow as it's encoded to signed
num = np.uint64(np.iinfo(np.int64).max)
self.assertEqual(np.uint64(ujson.decode(ujson.encode(num))), num)
示例10: quantization
def quantization(img, channels, r_bits=8, g_bits=8, b_bits=8):
img_out = None
if r_bits == 8 and r_bits == g_bits and r_bits == b_bits:
return img
if r_bits <= 16 and g_bits <= 16 and b_bits <= 16:
if r_bits < 8 or g_bits < 8 or b_bits < 8:
img_out = mediancut_algorithm(np_to_pil(img), 2 ** (r_bits+ g_bits + b_bits), np.array((r_bits, g_bits, b_bits)), channels)
else:
height = np.size(img,0)
width = np.size(img,1)
img_out = np.zeros(shape=img.shape, dtype=np.uint16)
for i in range (height):
for j in range (width):
if channels == 1:
aux = np.int(img[i][j]) / 255
img_out[i][j] = aux * ( 2 ** r_bits )
elif channels == 3:
r_aux = np.float(img[i][j][0]) / 255
g_aux = np.float(img[i][j][1]) / 255
b_aux = np.float(img[i][j][2]) / 255
new_r = np.uint16(r_aux * ( 2 ** r_bits ))
new_g = np.uint16(g_aux * ( 2 ** g_bits ))
new_b = np.uint16(b_aux * ( 2 ** b_bits ))
img_out[i, j] = np.array((new_r, new_g, new_b))
return img_out
示例11: write_sequence_file
def write_sequence_file(awgData, fileName, miniLLRepeat=1):
'''
Main function to pack channel LLs into an APS h5 file.
'''
#Preprocess the sequence data to handle APS restrictions
LLs12, repeat12, wfLib12 = preprocess(awgData['ch12']['linkList'],
awgData['ch12']['wfLib'],
awgData['ch12']['correctionT'])
LLs34, repeat34, wfLib34 = preprocess(awgData['ch34']['linkList'],
awgData['ch34']['wfLib'],
awgData['ch34']['correctionT'])
assert repeat12 == repeat34, 'Failed to unroll sequence'
if repeat12 != 0:
miniLLRepeat *= repeat12
#Merge the the marker data into the IQ linklists
merge_APS_markerData(LLs12, awgData['ch1m1']['linkList'], 1)
merge_APS_markerData(LLs12, awgData['ch2m1']['linkList'], 2)
merge_APS_markerData(LLs34, awgData['ch3m1']['linkList'], 1)
merge_APS_markerData(LLs34, awgData['ch4m1']['linkList'], 2)
#Open the HDF5 file
if os.path.isfile(fileName):
os.remove(fileName)
with h5py.File(fileName, 'w') as FID:
#List of which channels we have data for
#TODO: actually handle incomplete channel data
channelDataFor = [1,2] if LLs12 else []
channelDataFor += [3,4] if LLs34 else []
FID['/'].attrs['Version'] = 2.1
FID['/'].attrs['channelDataFor'] = np.uint16(channelDataFor)
FID['/'].attrs['miniLLRepeat'] = np.uint16(miniLLRepeat - 1)
#Create the waveform vectors
wfInfo = []
for wfLib in (wfLib12, wfLib34):
wfInfo.append(create_wf_vector({key:wf.real for key,wf in wfLib.items()}))
wfInfo.append(create_wf_vector({key:wf.imag for key,wf in wfLib.items()}))
LLData = [LLs12, LLs34]
repeats = [0, 0]
#Create the groups and datasets
for chanct in range(4):
chanStr = '/chan_{0}'.format(chanct+1)
chanGroup = FID.create_group(chanStr)
chanGroup.attrs['isIQMode'] = np.uint8(1)
#Write the waveformLib to file
FID.create_dataset('{0}/waveformLib'.format(chanStr), data=wfInfo[chanct][0])
#For A channels (1 & 3) we write link list data if we actually have any
if (np.mod(chanct,2) == 0) and LLData[chanct//2]:
groupStr = chanStr+'/linkListData'
LLGroup = FID.create_group(groupStr)
LLDataVecs, numEntries = create_LL_data(LLData[chanct//2], wfInfo[chanct][1], os.path.basename(fileName))
LLGroup.attrs['length'] = numEntries
for key,dataVec in LLDataVecs.items():
FID.create_dataset(groupStr+'/' + key, data=dataVec)
else:
chanGroup.attrs['isLinkListData'] = np.uint8(0)
示例12: test_valid
def test_valid(self):
prop = bcpp.Int()
assert prop.is_valid(None)
assert prop.is_valid(0)
assert prop.is_valid(1)
assert prop.is_valid(np.int8(0))
assert prop.is_valid(np.int8(1))
assert prop.is_valid(np.int16(0))
assert prop.is_valid(np.int16(1))
assert prop.is_valid(np.int32(0))
assert prop.is_valid(np.int32(1))
assert prop.is_valid(np.int64(0))
assert prop.is_valid(np.int64(1))
assert prop.is_valid(np.uint8(0))
assert prop.is_valid(np.uint8(1))
assert prop.is_valid(np.uint16(0))
assert prop.is_valid(np.uint16(1))
assert prop.is_valid(np.uint32(0))
assert prop.is_valid(np.uint32(1))
assert prop.is_valid(np.uint64(0))
assert prop.is_valid(np.uint64(1))
# TODO (bev) should fail
assert prop.is_valid(False)
assert prop.is_valid(True)
示例13: read_calibration_data
def read_calibration_data(self):
# Read calibration data
self.AC1 = numpy.int16(self.read_word(self.BMP183_REG['CAL_AC1']))
self.AC2 = numpy.int16(self.read_word(self.BMP183_REG['CAL_AC2']))
self.AC3 = numpy.int16(self.read_word(self.BMP183_REG['CAL_AC3']))
self.AC4 = numpy.uint16(self.read_word(self.BMP183_REG['CAL_AC4']))
self.AC5 = numpy.uint16(self.read_word(self.BMP183_REG['CAL_AC5']))
self.AC6 = numpy.uint16(self.read_word(self.BMP183_REG['CAL_AC6']))
self.B1 = numpy.int16(self.read_word(self.BMP183_REG['CAL_B1']))
self.B2 = numpy.int16(self.read_word(self.BMP183_REG['CAL_B2']))
self.MB = numpy.int16(self.read_word(self.BMP183_REG['CAL_MB']))
self.MC = numpy.int16(self.read_word(self.BMP183_REG['CAL_MC']))
self.MD = numpy.int16(self.read_word(self.BMP183_REG['CAL_MD']))
self.ID = numpy.int16(self.read_byte(self.BMP183_REG['ID']))
print "CALIBRATION DATA"
print "AC1: {0}".format(self.AC1)
print "AC2: {0}".format(self.AC2)
print "AC3: {0}".format(self.AC3)
print "AC4: {0}".format(self.AC4)
print "AC5: {0}".format(self.AC5)
print "B1: {0}".format(self.B1)
print "B2: {0}".format(self.B2)
print "MB: {0}".format(self.MB)
print "MC: {0}".format(self.MC)
print "MD: {0}".format(self.MD)
print "ID: {0}".format(self.ID)
print ""
示例14: testInt
def testInt(self):
num = np.int(2562010)
self.assertEqual(np.int(ujson.decode(ujson.encode(num))), num)
num = np.int8(127)
self.assertEqual(np.int8(ujson.decode(ujson.encode(num))), num)
num = np.int16(2562010)
self.assertEqual(np.int16(ujson.decode(ujson.encode(num))), num)
num = np.int32(2562010)
self.assertEqual(np.int32(ujson.decode(ujson.encode(num))), num)
num = np.int64(2562010)
self.assertEqual(np.int64(ujson.decode(ujson.encode(num))), num)
num = np.uint8(255)
self.assertEqual(np.uint8(ujson.decode(ujson.encode(num))), num)
num = np.uint16(2562010)
self.assertEqual(np.uint16(ujson.decode(ujson.encode(num))), num)
num = np.uint32(2562010)
self.assertEqual(np.uint32(ujson.decode(ujson.encode(num))), num)
num = np.uint64(2562010)
self.assertEqual(np.uint64(ujson.decode(ujson.encode(num))), num)
示例15: oldmovie
def oldmovie(src, dst):
graph = Image.open(src)
mask = Image.open('PhotoManager/Library/mask.png')
size = graph.size
width = size[0]
height = size[1]
mask = mask.resize((width, height))
mask = ny.uint16(ny.array(mask))
result = ny.uint16(ny.array(graph))
b = 10
g = 130
r = 200
gray = 0
for row in range(height):
for col in range(width):
gray = (result[row, col, 0] + result[row, col, 1] + result[row, col, 2]) / 3
b = mode(gray, b)
g = mode(gray, g)
r = mode(gray, r)
result[row, col, 0] = mode(b, mask[row, col, 0])
result[row, col, 1] = mode(g, mask[row, col, 1])
result[row, col, 2] = mode(r, mask[row, col, 2])
result = Image.fromarray(ny.uint8(result)).convert('RGB')
result.save(dst)
return 0