本文整理汇总了Python中skimage.exposure.adjust_gamma函数的典型用法代码示例。如果您正苦于以下问题:Python adjust_gamma函数的具体用法?Python adjust_gamma怎么用?Python adjust_gamma使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了adjust_gamma函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: compute_binary_diff_image
def compute_binary_diff_image(self, new_image):
"""
Compute an Otsu-thresholded image corresponding to the
absolute difference between the empty chessboard image and the
current image.
"""
adj_start_image = exposure.adjust_gamma(
color.rgb2gray(self.empty_chessboard_image), 0.1)
# gamma values have a strong impact on classification
adj_image = exposure.adjust_gamma(color.rgb2gray(new_image), 0.1)
diff_image = exposure.adjust_gamma(np.abs(adj_image - adj_start_image),
0.3)
return diff_image > threshold_otsu(diff_image)
开发者ID:superwhoopy,项目名称:chessreader,代码行数:13,代码来源:image_processor.py
示例2: image_prep
def image_prep(img):
# apply filters for better contrast and noise removal
img_gamma = adjust_gamma(img, 0.7)
img_median = median(img_gamma, disk(1))
# apply threshold
val = threshold_otsu(img_median)
img_otsu = img_median > val
# label image regions
label_image = label(img_otsu)
candidates = []
for region in regionprops(label_image):
minr, minc, maxr, maxc = region.bbox
if (maxr - minr > maxc - minc):
candidates.append(region)
# find numbers
areas = []
for candidate in candidates:
areas.append(candidate.area)
areas.sort()
areas.reverse()
n = 1
v = []
for candidate in candidates:
if (candidate.area == areas[0] or candidate.area == areas[1] or candidate.area == areas[2]):
v.append(candidate.image)
imsave('num%d.png' % n, candidate.image)
n += 1
return v
开发者ID:Xthtgeirf,项目名称:computer_vision,代码行数:33,代码来源:hw2.py
示例3: gen_thumbs
def gen_thumbs(dirname, key='/*/*decon.tif', where='host', level=2, figsize=6,
redo=True, gamma=1.0, **kwargs):
'''
Main function to generate and save thumbnail pngs
'''
# load data
data = load_data(dirname, key)
if data:
# can clean the dirnames here
foldername = os.path.abspath(dirname).split(os.path.sep)[-level]
if where == 'host':
save_name = 'Thumbs ' + foldername + '.png'
elif where == 'in folder':
save_name = os.path.abspath(
os.path.join(dirname, 'Thumbs ' + foldername + '.png'))
else:
save_name = os.path.abspath(
os.path.join(where, 'Thumbs ' + foldername + '.png'))
if not redo and os.path.exists(save_name):
print(save_name, "already exists, skipping")
return dirname + os.path.sep + key
data = {clean_dirname(k, figsize): adjust_gamma(abs(v), gamma)
for k, v in data.items()}
fig, ax = display_grid(data, figsize=figsize, **kwargs)
# make the layout 'tight'
fig.tight_layout()
# save the figure
print('Saving', save_name, 'on', os.getpid(), '...')
fig.savefig(save_name, bbox_inches='tight')
print('finished saving', save_name)
# mark data for gc
del data
return dirname + os.path.sep + key
开发者ID:david-hoffman,项目名称:scripts,代码行数:33,代码来源:thumbnail_generator.py
示例4: image_generate
def image_generate(img, ZCA_array) :
timg = np.copy(img)
timg = timg.transpose(1, 2, 0) # transpose to use skimage
augnum = random.randrange(0, 5)
if augnum==0 or augnum==1 :
# change nothing
pass
elif augnum==2 :
# horizontal flip
for j in range(3) :
timg[:,:,j] = np.fliplr(timg[:,:,j])
elif augnum==3 :
# random rotation of -15~15 degrees
angle = random.random()*30-15
timg = transform.rotate(timg/256.0, angle)
elif augnum==4 :
# gamma correction (luminance adjust) - random gamma 0.7~1.3
gamma = random.random()*0.6+0.7
timg = exposure.adjust_gamma(timg/256.0, gamma)
timg = timg.transpose(2, 0, 1)
# GCN, ZCA
for i in range(3) :
timg[i,:,:] -= np.mean(timg[i,:,:])
timg[i,:,:] /= np.std(timg[i,:,:])
timg[i,:,:] = np.dot(ZCA_array, timg[i,:,:].reshape(1024, 1)).reshape(32, 32)
return timg
开发者ID:shuuki4,项目名称:2015-2-ML,代码行数:29,代码来源:proj2_lenet1.py
示例5: gamma_correction
def gamma_correction(img=None, gamma=1., gain=1.):
r'''
Gamma correction or power law transform. It can be expressed as:
.. math::
I_{out} = gain \times {I_{in}} ^ {\gamma}
Adjusts contrast without changing the shape of the histogram. For the values
.. :math:`\gamma > 1` : Histogram shifts towards left (darker)
.. :math:`\gamma < 1` : Histogram shifts towards right (lighter)
Parameters
----------
img : array_like
Single image as numpy array or multiple images as array-like object
gamma : float
Non-negative real number
gain : float
Multiplying factor
References
----------
.. [1] http://scikit-image.org/docs/dev/auto_examples/color_exposure/plot_log_gamma.html # noqa
.. [2] http://en.wikipedia.org/wiki/Gamma_correction
'''
img_out = exposure.adjust_gamma(img, gamma, gain)
return img_out
开发者ID:jadelord,项目名称:TomoKTH,代码行数:28,代码来源:toolbox.py
示例6: save_segmented_image
def save_segmented_image(self, filepath_image, modality='t1c', show=False):
'''
Creates an image of original brain with segmentation overlay and save it in ./predictions
INPUT (1) str 'filepath_image': filepath to test image for segmentation, including file extension
(2) str 'modality': imaging modality to use as background. defaults to t1c. options: (flair, t1, t1c, t2)
(3) bool 'show': If true, shows output image. defaults to False.
OUTPUT (1) if show is True, shows image of segmentation results
(2) if show is false, returns segmented image.
'''
modes = {'flair': 0, 't1': 1, 't1c': 2, 't2': 3}
segmentation = self.predict_image(filepath_image, show=False)
print 'segmentation = ' + str(segmentation)
img_mask = np.pad(segmentation, (16, 16), mode='edge')
ones = np.argwhere(img_mask == 1)
twos = np.argwhere(img_mask == 2)
threes = np.argwhere(img_mask == 3)
fours = np.argwhere(img_mask == 4)
test_im = io.imread(filepath_image)
test_back = test_im.reshape(5, 216, 160)[modes[modality]]
# overlay = mark_boundaries(test_back, img_mask)
gray_img = img_as_float(test_back)
# adjust gamma of image
image = adjust_gamma(color.gray2rgb(gray_img), 0.65)
sliced_image = image.copy()
red_multiplier = [1, 0.2, 0.2]
yellow_multiplier = [1, 1, 0.25]
green_multiplier = [0.35, 0.75, 0.25]
blue_multiplier = [0, 0.25, 0.9]
print str(len(ones))
print str(len(twos))
print str(len(threes))
print str(len(fours))
# change colors of segmented classes
for i in xrange(len(ones)):
sliced_image[ones[i][0]][ones[i][1]] = red_multiplier
for i in xrange(len(twos)):
sliced_image[twos[i][0]][twos[i][1]] = green_multiplier
for i in xrange(len(threes)):
sliced_image[threes[i][0]][threes[i][1]] = blue_multiplier
for i in xrange(len(fours)):
sliced_image[fours[i][0]][fours[i][1]] = yellow_multiplier
#if show=True show the prediction
if show:
print 'Showing...'
io.imshow(sliced_image)
plt.show()
#save the prediction
print 'Saving...'
try:
mkdir_p('./predictions/')
io.imsave('./predictions/' + os.path.basename(filepath_image) + '.png', sliced_image)
print 'prediction saved.'
except:
io.imsave('./predictions/' + os.path.basename(filepath_image) + '.png', sliced_image)
print 'prediction saved.'
开发者ID:meghamattikalli,项目名称:nn-segmentation-for-lar,代码行数:60,代码来源:BrainSegDCNN_2.py
示例7: __prepare_image
def __prepare_image(image):
"""Prepare image for comparison"""
image = rgb2gray(image)
image = adjust_gamma(image)
image = pyramid_reduce(image, downscale=8)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
image = img_as_ubyte(image)
return image
开发者ID:IgorFedchenko,项目名称:FaceDetection,代码行数:9,代码来源:detect_face.py
示例8: S2_image_to_rgb
def S2_image_to_rgb(self, rgb_bands=("B11", "B08", "B03"), rgb_gamma=(1.0, 1.0, 1.0),hist_chop_off_fraction=0.01,
output_size=None,max_hist_pixel=1000**2,resample_order=3):
if output_size is None:
if self.target_resolution is None:
raise ValueError("output_size=None is only allowed for target_resolution != None")
else:
output_shape = list(self.final_shape)
else:
output_shape = [output_size,output_size]
rgb_type = np.uint8
S2_rgb = np.zeros(output_shape + [len(rgb_bands),],dtype=rgb_type)
if self.unit == "reflectance":
bins = np.linspace(0.0,1.0,100 / 2.0)
elif self.unit == "dn":
bins = np.linspace(0,10000,100 / 2.0)
for i_rgb, (band, gamma) in enumerate(zip(rgb_bands, rgb_gamma)):
if self.target_resolution is None:
data = self.data[band]
else:
i_band = self.band_list.index(band)
data = self.data[:,:,i_band]
if self.bad_data_value is np.NAN:
bf = data[:,:][np.isfinite(data[:,:])]
else:
bf = data[:,:][data[:,:] == self.bad_data_value]
pixel_skip = np.int(np.floor(bf.shape[0] / max_hist_pixel) + 1)
bf = bf[::pixel_skip]
hh, xx = np.histogram(bf, bins=bins,normed=False)
bb = 0.5 * (xx[1:] + xx[:-1])
hist_chop_off = hist_chop_off_fraction * np.sum(hh) / len(bins)
lim = (lambda x: (np.min(x), np.max(x)))(bb[hh > hist_chop_off])
zoom_factor = np.array(output_shape) / np.array(data[:,:].shape)
zm = np.nan_to_num(np.array(data[:, :],dtype=np.float32))
if (zoom_factor != [1.0,1.0]).all():
self.logger.info("Resample band for RGB image: %i,%s,zoom:%.2f" % (i_rgb, band,zoom_factor[0]))
zm = zoom(input=zm,zoom=zoom_factor,order=resample_order)
bf = rescale_intensity(image=zm,in_range=lim,out_range=(0.0, 255.0))
S2_rgb[:, :, i_rgb] = np.array(bf,dtype=rgb_type)
self.logger.info("Rescale band for RGB image: %i,%s,(%.2f,%.2f)->(0,256), zoom:%.2f" %
(i_rgb, band, lim[0], lim[1],zoom_factor[0]))
if gamma != 0.0:
S2_rgb[:, :, i_rgb] = np.array(
adjust_gamma(np.array(S2_rgb[:, :, i_rgb], dtype=np.float32),gamma),dtype=rgb_type)
return S2_rgb
开发者ID:hollstein,项目名称:S2MSI,代码行数:54,代码来源:S2Image.py
示例9: make_square
def make_square(img):
height, width = img.shape
max_side = max([height, width])
copy = np.zeros(shape=(max_side, max_side), dtype=np.uint8)
copy.fill(255)
for i in range(height):
for j in range(width):
copy[i][j] = img[i][j]
# increase contrast a bit with a gamma correction
copy = exposure.adjust_gamma(copy, gamma=1.8)
return copy
开发者ID:deccs,项目名称:ndsb_theano,代码行数:12,代码来源:load_images.py
示例10: transform
def transform(self, Xb, yb):
Xb, yb = super(AdjustGammaBatchIteratorMixin, self).transform(Xb, yb)
Xb_transformed = Xb.copy()
if self.adjust_gamma_p > 0:
random_idx = get_random_idx(Xb, self.adjust_gamma_p)
for i in random_idx:
gamma = choice(self.adjust_gamma_chocies)
Xb_transformed[i] = adjust_gamma(
Xb[i].transpose(1, 2, 0), gamma=gamma
).transpose(2, 0, 1)
return Xb_transformed, yb
开发者ID:Lomascolo,项目名称:nolearn_utils,代码行数:13,代码来源:iterators.py
示例11: call
def call(self, image, saliency_image):
img_resize = resize(image, saliency_image.shape)
saliency_range = max(0.15, saliency_image.max() - saliency_image.min())
saliency_norm = (saliency_image - saliency_image.min()) / saliency_range
saliency_gamma = adjust_gamma(saliency_norm, gamma=self.gamma)
cmap = matplotlib.cm.get_cmap('viridis')
cmap_hsv = rgb2hsv(cmap(saliency_gamma)[:, :, :3])
hsv = np.stack([
cmap_hsv[:, :, 0],
saliency_gamma,
img_resize
], axis=-1)
return hsv2rgb(hsv)
开发者ID:BioroboticsLab,项目名称:bb_pipeline,代码行数:13,代码来源:visualization.py
示例12: save_segmented_image
def save_segmented_image(self, index, test_img, save=False):
"""
Creates an image of original brain with segmentation overlay
:param index: index of image to save
:param test_img: filepath to test image for segmentation, including file extension
:param save: If true, shows output image. (defaults to False)
:return: if show is True, shows image of segmentation results
if show is false, returns segmented image.
"""
segmentation = self.predict_image(test_img)
img_mask = np.pad(segmentation, (16, 16), mode='edge')
ones = np.argwhere(img_mask == 1)
twos = np.argwhere(img_mask == 2)
threes = np.argwhere(img_mask == 3)
fours = np.argwhere(img_mask == 4)
test_im = mpimg.imread(test_img).astype('float')
test_back = rgb2gray(test_im).reshape(5, 216, 160)[-2]
# overlay = mark_boundaries(test_back, img_mask)
gray_img = img_as_float(test_back)
# adjust gamma of image
image = adjust_gamma(color.gray2rgb(gray_img), 0.65)
sliced_image = image.copy()
red_multiplier = [1, 0.2, 0.2]
yellow_multiplier = [1, 1, 0.25]
green_multiplier = [0.35, 0.75, 0.25]
blue_multiplier = [0, 0.25, 0.9]
# change colors of segmented classes
for i in xrange(len(ones)):
sliced_image[ones[i][0]][ones[i][1]] = red_multiplier
for i in xrange(len(twos)):
sliced_image[twos[i][0]][twos[i][1]] = green_multiplier
for i in xrange(len(threes)):
sliced_image[threes[i][0]][threes[i][1]] = blue_multiplier
for i in xrange(len(fours)):
sliced_image[fours[i][0]][fours[i][1]] = yellow_multiplier
if save:
try:
mkdir_p('./results/')
io.imsave('./results/result' + '_' + str(index) + '.png', sliced_image)
except:
io.imsave('./results/result' + '_' + str(index) + '.png', sliced_image)
else:
return sliced_image
开发者ID:meghamattikalli,项目名称:nn-segmentation-for-lar,代码行数:50,代码来源:brain_tumor_segmentation_models.py
示例13: test_adjust_gamma_greater_one
def test_adjust_gamma_greater_one():
"""Verifying the output with expected results for gamma
correction with gamma equal to two"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
expected = np.array([[ 0, 0, 0, 0, 1, 1, 2, 3],
[ 4, 5, 6, 7, 9, 10, 12, 14],
[ 16, 18, 20, 22, 25, 27, 30, 33],
[ 36, 39, 42, 45, 49, 52, 56, 60],
[ 64, 68, 72, 76, 81, 85, 90, 95],
[100, 105, 110, 116, 121, 127, 132, 138],
[144, 150, 156, 163, 169, 176, 182, 189],
[196, 203, 211, 218, 225, 233, 241, 249]], dtype=np.uint8)
result = exposure.adjust_gamma(image, 2)
assert_array_equal(result, expected)
开发者ID:bernardndegwa,项目名称:scikit-image,代码行数:15,代码来源:test_exposure.py
示例14: test_adjust_gamma_less_one
def test_adjust_gamma_less_one():
"""Verifying the output with expected results for gamma
correction with gamma equal to half"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
expected = np.array([[ 0, 31, 45, 55, 63, 71, 78, 84],
[ 90, 95, 100, 105, 110, 115, 119, 123],
[127, 131, 135, 139, 142, 146, 149, 153],
[156, 159, 162, 165, 168, 171, 174, 177],
[180, 183, 186, 188, 191, 194, 196, 199],
[201, 204, 206, 209, 211, 214, 216, 218],
[221, 223, 225, 228, 230, 232, 234, 236],
[238, 241, 243, 245, 247, 249, 251, 253]], dtype=np.uint8)
result = exposure.adjust_gamma(image, 0.5)
assert_array_equal(result, expected)
开发者ID:bernardndegwa,项目名称:scikit-image,代码行数:15,代码来源:test_exposure.py
示例15: augment_image
def augment_image(img):
"""
Augment an image using a combination of lightening, darkening, rotation and mirror images.
:params img: Image as numpy array
:return: array of augmented images
"""
augmented_images = []
augmented_images.append(np.fliplr(img))
for g in [0.45, 0.65, 0.85, 1.25, 1.5, 2]:
new_img = exposure.adjust_gamma(img, gamma=g)
augmented_images.append(new_img)
augmented_images.append(np.fliplr(new_img))
new_img = transform.rotate(img, 180)
augmented_images.append(new_img)
augmented_images.append(np.fliplr(new_img))
return np.array(augmented_images)
开发者ID:simonb83,项目名称:DataScienceIntensive,代码行数:16,代码来源:augmented_predict.py
示例16: show_segmented_image
def show_segmented_image(self, test_img, modality='t1c', show = False):
'''
Creates an image of original brain with segmentation overlay
INPUT (1) str 'test_img': filepath to test image for segmentation, including file extension
(2) str 'modality': imaging modelity to use as background. defaults to t1c. options: (flair, t1, t1c, t2)
(3) bool 'show': If true, shows output image. defaults to False.
OUTPUT (1) if show is True, shows image of segmentation results
(2) if show is false, returns segmented image.
'''
modes = {'flair':0, 't1':1, 't1c':2, 't2':3}
segmentation = self.predict_image(test_img, show=False)
img_mask = np.pad(segmentation, (16,16), mode='edge')
ones = np.argwhere(img_mask == 1)
twos = np.argwhere(img_mask == 2)
threes = np.argwhere(img_mask == 3)
fours = np.argwhere(img_mask == 4)
test_im = io.imread(test_img)
test_back = test_im.reshape(5,240,240)[-2]
# overlay = mark_boundaries(test_back, img_mask)
gray_img = img_as_float(test_back)
# adjust gamma of image
image = adjust_gamma(color.gray2rgb(gray_img), 0.65)
sliced_image = image.copy()
red_multiplier = [1, 0.2, 0.2]
yellow_multiplier = [1,1,0.25]
green_multiplier = [0.35,0.75,0.25]
blue_multiplier = [0,0.25,0.9]
# change colors of segmented classes
for i in xrange(len(ones)):
sliced_image[ones[i][0]][ones[i][1]] = red_multiplier
for i in xrange(len(twos)):
sliced_image[twos[i][0]][twos[i][1]] = green_multiplier
for i in xrange(len(threes)):
sliced_image[threes[i][0]][threes[i][1]] = blue_multiplier
for i in xrange(len(fours)):
sliced_image[fours[i][0]][fours[i][1]] = yellow_multiplier
if show:
io.imshow(sliced_image)
plt.show()
else:
return sliced_image
开发者ID:naldeborgh7575,项目名称:brain_segmentation,代码行数:47,代码来源:Segmentation_Models.py
示例17: image_transformation
def image_transformation(X, method_type='blur', **kwargs):
# https://www.kaggle.com/tomahim/image-manipulation-augmentation-with-skimage
q = kwargs['percentile'] if 'percentile' in kwargs else (0.2, 99.8)
angle = kwargs['angle'] if 'angle' in kwargs else 60
transformation_dict = {
'blur': normalize(ndimage.uniform_filter(X)),
'invert': normalize(util.invert(X)),
'rotate': rotate(X, angle=angle),
'rescale_intensity': _rescale_intensity(X, q=q),
'gamma_correction': exposure.adjust_gamma(X, gamma=0.4, gain=0.9),
'log_correction': exposure.adjust_log(X),
'sigmoid_correction': exposure.adjust_sigmoid(X),
'horizontal_flip': X[:, ::-1],
'vertical_flip': X[::-1, :],
'rgb2gray': skimage.color.rgb2gray(X)
}
return transformation_dict[method_type]
开发者ID:ashishyadavppe,项目名称:Skater,代码行数:17,代码来源:image_ops.py
示例18: enhance_patches
def enhance_patches(_img, _patches, _gamma=0.2):
"""
Emphasize a set of rectangular regions from an image. The original image is altered such that
the regions of interest appear enhanced.
:param _img: numpy.ndarray
original image
:param _patches: list
list of 4-elements vectors indicating the coordinates of patches of interest
:param _gamma: float
gamma adjustment for "background" image
:return:
"""
_res = adjust_gamma(_img, _gamma)
for p in _patches:
_res[p[0]:p[1], p[2]:p[3]] = _img[p[0]:p[1], p[2]:p[3]]
return _res
开发者ID:gitter-badger,项目名称:WSItk,代码行数:20,代码来源:visualization.py
示例19: transform_features
def transform_features(data):
with open('transformed_test_inputs.csv', 'wb') as csvfile:
d = get_circle_filter(48,48)
# writer = csv.writer(csvfile)
# writer.writerow(["Id", "Prediction"])
out_data = []
i = 1
bar = pyprind.ProgBar(len(data), title="Transforming raw features")
for row in data:
# from (2304,) to (48,48) because i wrote the functions for 2d , can optimize later
m = a2m(row)
dm = deskew(apply_filter(exposure.adjust_gamma(m,0.4), d))
dm = dm-get_dilated(dm)*0.5
out_data.append(dm.flatten())
# print len(dm.flattenedten())
r = "%s," % str(i)
for j in dm.flatten():
r += "%s," % str(j)
csvfile.write(r[:-1] + "\n")
i += 1
bar.update()
return out_data
开发者ID:imcpr,项目名称:Modified_Digits_Classification,代码行数:22,代码来源:features.py
示例20: test_adjust_gamma_zero
def test_adjust_gamma_zero():
"""White image should be returned for gamma equal to zero"""
image = np.random.uniform(0, 255, (8, 8))
result = exposure.adjust_gamma(image, 0)
dtype = image.dtype.type
assert_array_equal(result, dtype_range[dtype][1])
开发者ID:ameya005,项目名称:scikit-image,代码行数:6,代码来源:test_exposure.py
注:本文中的skimage.exposure.adjust_gamma函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论