本文整理汇总了Python中numpy.uint16函数的典型用法代码示例。如果您正苦于以下问题:Python uint16函数的具体用法?Python uint16怎么用?Python uint16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uint16函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 #浮点像素坐标值
开发者ID:diamond2nv,项目名称:pyNVscan,代码行数:33,代码来源:pyNVscan_AT_CV_hot_spot.V3.1_o3.py
示例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
开发者ID:signaldetect,项目名称:fractality,代码行数:26,代码来源:image.py
示例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
开发者ID:signaldetect,项目名称:fractality,代码行数:26,代码来源:image.py
示例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
开发者ID:westin87,项目名称:hexapi,代码行数:7,代码来源:orientation.py
示例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)
开发者ID:lgo33,项目名称:synacor_vm,代码行数:7,代码来源:vm.py
示例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
开发者ID:benoxoft,项目名称:adventofcode,代码行数:7,代码来源:day7.py
示例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)))
开发者ID:PyAndy,项目名称:Py3NES,代码行数:29,代码来源:cpu.py
示例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) )
开发者ID:noum,项目名称:stimuli,代码行数:25,代码来源:eizoGS320.py
示例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)
开发者ID:paddymul,项目名称:pandas,代码行数:29,代码来源:test_ujson.py
示例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
开发者ID:mateus558,项目名称:Trabalho-1-de-processamento-de-Imagens,代码行数:32,代码来源:Quantization.py
示例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)
开发者ID:ahelsing,项目名称:QGL,代码行数:60,代码来源:APSPattern.py
示例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)
开发者ID:jakirkham,项目名称:bokeh,代码行数:28,代码来源:test_primitive.py
示例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 ""
开发者ID:Mausy5043,项目名称:bmp183,代码行数:27,代码来源:bmp183.py
示例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)
开发者ID:paddymul,项目名称:pandas,代码行数:27,代码来源:test_ujson.py
示例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
开发者ID:39M,项目名称:PhotoTheater,代码行数:28,代码来源:filter_lib.py
示例16: pack_waveform
def pack_waveform(analog, marker1, marker2):
'''
Helper function to convert a floating point analog channel and two logical marker channel to a sequence of 16bit integers.
AWG 5000 series binary data format
m2 m1 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1
16-bit format with markers occupying left 2 bits followed by the 14 bit
analog channel value
'''
#Convert decimal shape on [-1,1] to binary on [0,2^14 (16383)]
#AWG actually makes 111,111,111,111,10 the 100% output, and
# 111,111,111,111,11 is one step larger than 100% output so we
# ignore the one extra positive number and scale from [0,16382]
analog[analog>1] = 1.0
analog[analog<-1] = -1.0
maxLength = max(analog.size, marker1.size, marker2.size)
if marker1.size < maxLength:
marker1 = np.append(marker1, np.zeros(maxLength-marker1.size, dtype=np.bool))
if marker2.size < maxLength:
marker2 = np.append(marker2, np.zeros(maxLength-marker2.size, dtype=np.bool))
if analog.size < maxLength:
analog = np.append(analog, np.zeros(maxLength-analog.size, dtype=np.float64))
binData = np.uint16( MAX_WAVEFORM_VALUE*analog + MAX_WAVEFORM_VALUE );
binData += 2**14*np.uint16(marker1) + 2**15*np.uint16(marker2)
return binData
开发者ID:Plourde-Research-Lab,项目名称:PyQLab,代码行数:29,代码来源:TekPattern.py
示例17: getMarkupTab
def getMarkupTab(image):
#fallback margin size approximation so we can exit
left = 0
top = 0
height, width = image.shape[:2]
print "{width} x {height}".format(width=width, height=height)
## Iterate over the width then by height until we find a pixel red enough to make a decision
for x in xrange(width):
for y in xrange(height):
# Check individual pixel values
pixel = image[y,x]
b, g, r = pixel
temp_gb = np.uint16(g) + np.uint16(b)
# Checking the green blue and red threshold values
if r > 200 and temp_gb < 320:
return image[ top : height, left : x]
return None
开发者ID:andrew749,项目名称:Note-it-Now,代码行数:25,代码来源:cropmarkup.py
示例18: initialize
def initialize(data, mode):
# mapping index to user name and book isbn
n = len(data)
p = len(user_list) + len(book_list)
x = ss.lil_matrix((n, p), dtype=np.uint16)
y = np.zeros((n, 1), dtype=np.float)
for row, entry in enumerate(data):
user = entry["user"]
isbn = entry["isbn"]
user_i = id_i[user]
isbn_i = id_i[isbn]
x[row, user_i] = np.uint16(1)
x[row, isbn_i] = np.uint16(1)
if mode == "train":
rating = entry["rating"]
y[row] = np.float(rating)
if mode == "train":
y -= train_mean
x = ss.csc_matrix(x)
# xtx = x.transpose().dot(x)
# xty = x.transpose().dot(y)
return x, y
else:
return x
开发者ID:vincentli2010,项目名称:cs181,代码行数:27,代码来源:baseline_l2.py
示例19: initialize
def initialize(data):
# mapping index to user name and book isbn
n = len(data); p = len(user_list) + len(book_list)
x = ss.lil_matrix((n,p), dtype = np.uint16)
y = np.zeros((n,1), dtype = np.float)
row = 0
counter = 0
for entry in data:
counter += 1
if counter % 10000 == 0:
print int(counter/n * 100)
user = entry['user']; isbn = entry['isbn']; rating = entry['rating']
user_i = id_i[user]; isbn_i = id_i[isbn]
x[row, user_i] = np.uint16(1)
x[row, isbn_i] = np.uint16(1)
y[row] = np.float(rating)
row += 1
y -= global_mean
x = ss.csc_matrix(x)
#xtx = x.transpose().dot(x)
#xty = x.transpose().dot(y)
return x, y
开发者ID:ayoung01,项目名称:cs181,代码行数:27,代码来源:baseline_l2_compute.py
示例20: galois_lfsr
def galois_lfsr(seed, taps):
seed = np.uint16(seed)
taps = np.uint16(taps)
start_state = np.uint16(seed) # Any nonzero start state will work
arg = "start_state \t\t%s" % bin(start_state)
print(arg)
lf_state_register = np.uint16(start_state)
period = 0
bit_sequence = []
while True:
lsb = lf_state_register & 1 # /* Get LSB (i.e., the output bit). */
bit_sequence.append(lsb)
lf_state_register >>= 1 # /* Shift register */
lf_state_register ^= (-lsb) & taps # /* If the output bit is 1, apply toggle mask.
# * The value has 1 at bits corresponding
# * to taps, 0 elsewhere. */
period += 1
# arg = "lf_state_register \t%s" % bin(lf_state_register)
# print(arg)
if lf_state_register == start_state:
break
# arg = "bit_sequence[0] %s" % bit_sequence[0]
# print(arg)
# arg = "bit_sequence[1] %s" % bit_sequence[1]
# print(arg)
return bit_sequence
开发者ID:spel-uchile,项目名称:SeismicScripts,代码行数:27,代码来源:ss_signalGenerator.py
注:本文中的numpy.uint16函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论