本文整理汇总了Python中numpy.uint16方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.uint16方法的具体用法?Python numpy.uint16怎么用?Python numpy.uint16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.uint16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def execute(self):
img_h = self.img.shape[0]
img_w = self.img.shape[1]
img_c = self.img.shape[2]
gc_img = np.empty((img_h, img_w, img_c), np.uint16)
for y in range(self.img.shape[0]):
for x in range(self.img.shape[1]):
if self.mode == 'rgb':
gc_img[y, x, 0] = self.lut[self.img[y, x, 0]]
gc_img[y, x, 1] = self.lut[self.img[y, x, 1]]
gc_img[y, x, 2] = self.lut[self.img[y, x, 2]]
gc_img[y, x, :] = gc_img[y, x, :] / 4
elif self.mode == 'yuv':
gc_img[y, x, 0] = self.lut[0][self.img[y, x, 0]]
gc_img[y, x, 1] = self.lut[1][self.img[y, x, 1]]
gc_img[y, x, 2] = self.lut[1][self.img[y, x, 2]]
self.img = gc_img
return self.img
示例2: execute
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def execute(self):
img_pad = self.padding()
img_pad = img_pad.astype(np.uint16)
raw_h = self.img.shape[0]
raw_w = self.img.shape[1]
nlm_img = np.empty((raw_h, raw_w), np.uint16)
kernel = np.ones((2*self.ds+1, 2*self.ds+1)) / pow(2*self.ds+1, 2)
for y in range(img_pad.shape[0] - 2 * self.Ds):
for x in range(img_pad.shape[1] - 2 * self.Ds):
center_y = y + self.Ds
center_x = x + self.Ds
sweight, average, wmax = self.calWeights(img_pad, kernel, center_y, center_x)
average = average + wmax * img_pad[center_y, center_x]
sweight = sweight + wmax
nlm_img[y,x] = average / sweight
self.img = nlm_img
return self.clipping()
示例3: execute
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def execute(self):
img_pad = self.padding()
raw_h = self.img.shape[0]
raw_w = self.img.shape[1]
aaf_img = np.empty((raw_h, raw_w), np.uint16)
for y in range(img_pad.shape[0] - 4):
for x in range(img_pad.shape[1] - 4):
p0 = img_pad[y + 2, x + 2]
p1 = img_pad[y, x]
p2 = img_pad[y, x + 2]
p3 = img_pad[y, x + 4]
p4 = img_pad[y + 2, x]
p5 = img_pad[y + 2, x + 4]
p6 = img_pad[y + 4, x]
p7 = img_pad[y + 4, x + 2]
p8 = img_pad[y + 4, x + 4]
aaf_img[y, x] = (p0 * 8 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 16
self.img = aaf_img
return self.img
示例4: test_subheader
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_subheader(self):
assert_equal(self.subhdr.get_shape() , (10,10,3))
assert_equal(self.subhdr.get_nframes() , 1)
assert_equal(self.subhdr.get_nframes(),
len(self.subhdr.subheaders))
assert_equal(self.subhdr._check_affines(), True)
assert_array_almost_equal(np.diag(self.subhdr.get_frame_affine()),
np.array([ 2.20241979, 2.20241979, 3.125, 1.]))
assert_equal(self.subhdr.get_zooms()[0], 2.20241978764534)
assert_equal(self.subhdr.get_zooms()[2], 3.125)
assert_equal(self.subhdr._get_data_dtype(0),np.uint16)
#assert_equal(self.subhdr._get_frame_offset(), 1024)
assert_equal(self.subhdr._get_frame_offset(), 1536)
dat = self.subhdr.raw_data_from_fileobj()
assert_equal(dat.shape, self.subhdr.get_shape())
scale_factor = self.subhdr.subheaders[0]['scale_factor']
assert_equal(self.subhdr.subheaders[0]['scale_factor'].item(),1.0)
ecat_calib_factor = self.hdr['ecat_calibration_factor']
assert_equal(ecat_calib_factor, 25007614.0)
示例5: test_able_int_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_able_int_type():
# The integer type cabable of containing values
for vals, exp_out in (
([0, 1], np.uint8),
([0, 255], np.uint8),
([-1, 1], np.int8),
([0, 256], np.uint16),
([-1, 128], np.int16),
([0.1, 1], None),
([0, 2**16], np.uint32),
([-1, 2**15], np.int32),
([0, 2**32], np.uint64),
([-1, 2**31], np.int64),
([-1, 2**64-1], None),
([0, 2**64-1], np.uint64),
([0, 2**64], None)):
assert_equal(able_int_type(vals), exp_out)
示例6: test_can_cast
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_can_cast():
tests = ((np.float32, np.float32, True, True, True),
(np.float64, np.float32, True, True, True),
(np.complex128, np.float32, False, False, False),
(np.float32, np.complex128, True, True, True),
(np.float32, np.uint8, False, True, True),
(np.uint32, np.complex128, True, True, True),
(np.int64, np.float32, True, True, True),
(np.complex128, np.int16, False, False, False),
(np.float32, np.int16, False, True, True),
(np.uint8, np.int16, True, True, True),
(np.uint16, np.int16, False, True, True),
(np.int16, np.uint16, False, False, True),
(np.int8, np.uint16, False, False, True),
(np.uint16, np.uint8, False, True, True),
)
for intype, outtype, def_res, scale_res, all_res in tests:
assert_equal(def_res, can_cast(intype, outtype))
assert_equal(scale_res, can_cast(intype, outtype, False, True))
assert_equal(all_res, can_cast(intype, outtype, True, True))
示例7: apply_using_lut
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def apply_using_lut(input_band, transformation):
'''Applies a linear transformation to an array using a look up table.
This creates a uint16 array as the output and clips the output band
to the range of a uint16.
:param array input_band: A 2D array representing the image data of the
a single band
:param LinearTransformation transformation: A LinearTransformation
(gain and offset)
:returns: A 2D array of of the input_band with the transformation applied
'''
logging.info('Normalize: Applying linear transformation to band (uint16)')
def _apply_lut(band, lut):
'''Changes band intensity values based on intensity look up table (lut)
'''
if lut.dtype != band.dtype:
raise Exception(
'Band ({}) and lut ({}) must be the same data type.').format(
band.dtype, lut.dtype)
return numpy.take(lut, band, mode='clip')
lut = _linear_transformation_to_lut(transformation)
return _apply_lut(input_band, lut)
示例8: _uniform_weight_alpha
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def _uniform_weight_alpha(sum_masked_arrays, output_datatype):
'''Calculates the cumulative mask of a list of masked array
Input:
sum_masked_arrays (list of numpy masked arrays): The list of
masked arrays to find the cumulative mask of, each element
represents one band.
(sums_masked_array.mask has a 1 for a no data pixel and
a 0 otherwise)
output_datatype (numpy datatype): The output datatype
Output:
output_alpha (numpy uint16 array): The output mask
(0 for a no data pixel, uint16 max value otherwise)
'''
output_alpha = numpy.ones(sum_masked_arrays[0].shape)
for band_sum_masked_array in sum_masked_arrays:
output_alpha[numpy.nonzero(band_sum_masked_array.mask == 1)] = 0
output_alpha = output_alpha.astype(output_datatype) * \
numpy.iinfo(output_datatype).max
return output_alpha
示例9: test_save_with_compress
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_save_with_compress(self):
output_file = 'test_save_with_compress.tif'
test_band = numpy.array([[5, 2, 2], [1, 6, 8]], dtype=numpy.uint16)
test_alpha = numpy.array([[0, 0, 0], [1, 1, 1]], dtype=numpy.bool)
test_gimage = gimage.GImage([test_band, test_band, test_band],
test_alpha, self.metadata)
gimage.save(test_gimage, output_file, compress=True)
result_gimg = gimage.load(output_file)
numpy.testing.assert_array_equal(result_gimg.bands[0], test_band)
numpy.testing.assert_array_equal(result_gimg.bands[1], test_band)
numpy.testing.assert_array_equal(result_gimg.bands[2], test_band)
numpy.testing.assert_array_equal(result_gimg.alpha, test_alpha)
self.assertEqual(result_gimg.metadata, self.metadata)
os.unlink(output_file)
示例10: format_time
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def format_time(running_time):
"""Format time in seconds as hours:minutes:seconds.
PARAMETERS
----------
running_time : float
Time in seconds.
RETURNS
----------
running_time : str
The time formatted as hours:minutes:seconds.
"""
hrs = np.uint16(np.floor(running_time/(60.**2)))
mts = np.uint16(np.floor(running_time/60.-hrs*60))
sec = np.uint16(np.round(running_time-hrs*60.**2-mts*60.))
return "{:02d}:{:02d}:{:02d}".format(hrs,mts,sec)
示例11: squeeze_bits
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def squeeze_bits(arr: numpy.ndarray) -> numpy.ndarray:
"""Return a copy of an integer numpy array with the minimum bitness."""
assert arr.dtype.kind in ("i", "u")
if arr.size == 0:
return arr
if arr.dtype.kind == "i":
assert arr.min() >= 0
mlbl = int(arr.max()).bit_length()
if mlbl <= 8:
dtype = numpy.uint8
elif mlbl <= 16:
dtype = numpy.uint16
elif mlbl <= 32:
dtype = numpy.uint32
else:
dtype = numpy.uint64
return arr.astype(dtype)
示例12: group_years
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def group_years(years, interval=3):
""" Return integers representing sequential groupings of years
Note: years specified must be sorted
Args:
years (np.ndarray): the year corresponding to each EVI value
interval (int, optional): number of years to group together
(default: 3)
Returns:
np.ndarray: integers representing sequential year groupings
"""
n_groups = math.ceil((years.max() - years.min()) / interval)
if n_groups <= 1:
return np.zeros_like(years, dtype=np.uint16)
splits = np.array_split(np.arange(years.min(), years.max() + 1), n_groups)
groups = np.zeros_like(years, dtype=np.uint16)
for i, s in enumerate(splits):
groups[np.in1d(years, s)] = i
return groups
示例13: ordinal2yeardoy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def ordinal2yeardoy(ordinal):
""" Convert ordinal dates to two arrays of year and doy
Args:
ordinal (np.ndarray): ordinal dates
Returns:
np.ndarray: nobs x 2 np.ndarray containing the year and DOY for each
ordinal date
"""
_date = [dt.fromordinal(_d) for _d in ordinal]
yeardoy = np.empty((ordinal.size, 2), dtype=np.uint16)
yeardoy[:, 0] = np.array([int(_d.strftime('%Y')) for _d in _date])
yeardoy[:, 1] = np.array([int(_d.strftime('%j')) for _d in _date])
return yeardoy
示例14: test_padded_union
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_padded_union(self):
dt = np.dtype(dict(
names=['a', 'b'],
offsets=[0, 0],
formats=[np.uint16, np.uint32],
itemsize=5,
))
ct = np.ctypeslib.as_ctypes_type(dt)
assert_(issubclass(ct, ctypes.Union))
assert_equal(ctypes.sizeof(ct), dt.itemsize)
assert_equal(ct._fields_, [
('a', ctypes.c_uint16),
('b', ctypes.c_uint32),
('', ctypes.c_char * 5), # padding
])
示例15: test_basic
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uint16 [as 别名]
def test_basic(self):
ba = [1, 2, 10, 11, 6, 5, 4]
ba2 = [[1, 2, 3, 4], [5, 6, 7, 9], [10, 3, 4, 5]]
for ctype in [np.int8, np.uint8, np.int16, np.uint16, np.int32,
np.uint32, np.float32, np.float64, np.complex64,
np.complex128]:
a = np.array(ba, ctype)
a2 = np.array(ba2, ctype)
tgt = np.array([1, 3, 13, 24, 30, 35, 39], ctype)
assert_array_equal(np.cumsum(a, axis=0), tgt)
tgt = np.array(
[[1, 2, 3, 4], [6, 8, 10, 13], [16, 11, 14, 18]], ctype)
assert_array_equal(np.cumsum(a2, axis=0), tgt)
tgt = np.array(
[[1, 3, 6, 10], [5, 11, 18, 27], [10, 13, 17, 22]], ctype)
assert_array_equal(np.cumsum(a2, axis=1), tgt)