本文整理匯總了Python中skimage.color方法的典型用法代碼示例。如果您正苦於以下問題:Python skimage.color方法的具體用法?Python skimage.color怎麽用?Python skimage.color使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skimage
的用法示例。
在下文中一共展示了skimage.color方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_label_colortable
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def get_label_colortable(n_labels, shape):
if cv2 is None:
raise RuntimeError('get_label_colortable requires OpenCV (cv2)')
rows, cols = shape
if rows * cols < n_labels:
raise ValueError
cmap = label_colormap(n_labels)
table = np.zeros((rows * cols, 50, 50, 3), dtype=np.uint8)
for lbl_id, color in enumerate(cmap):
color_uint8 = (color * 255).astype(np.uint8)
table[lbl_id, :, :] = color_uint8
text = '{:<2}'.format(lbl_id)
cv2.putText(table[lbl_id], text, (5, 35),
cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 3)
table = table.reshape(rows, cols, 50, 50, 3)
table = table.transpose(0, 2, 1, 3, 4)
table = table.reshape(rows * 50, cols * 50, 3)
return table
# -----------------------------------------------------------------------------
# Evaluation
# -----------------------------------------------------------------------------
示例2: check_duplicated_color
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def check_duplicated_color(text):
SENTENCE_SPLIT_REGEX = re.compile(r'(\W+)')
words = SENTENCE_SPLIT_REGEX.split(text.strip())
words = [w.lower() for w in words if len(w.strip()) > 0]
sky_color = ''
ground_color = ''
for word in words:
if word in ALL_COLOR:
if sky_color == '':
sky_color = word
else:
ground_color = word
break
if sky_color == ground_color:
raise Exception('It is not recommended to use the same sky and ground color.')
示例3: load_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def load_image(self, image_index):
path = self.image_path(image_index)
img = skimage.io.imread(path)
if len(img.shape) == 1:
img = img[0]
if len(img.shape) == 2:
img = skimage.color.gray2rgb(img)
try:
return img.astype(np.float32) / 255.0
except Exception:
print (path)
exit(0)
示例4: load_image
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def load_image(self, image_index):
image_info = self.coco.loadImgs(self.image_ids[image_index])[0]
path = os.path.join(self.root_dir, 'images', self.set_name, image_info['file_name'])
img = skimage.io.imread(path)
if len(img.shape) == 2:
img = skimage.color.gray2rgb(img)
return img.astype(np.float32)/255.0
示例5: preprocess
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def preprocess(self, image, imagesize):
image = skimage.color.rgb2gray(image)
image = skimage.transform.resize(image, imagesize, mode='constant')
image = skimage.exposure.rescale_intensity(image, out_range=(0, 255))
image = image / 255.0
return image
示例6: plotRect
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def plotRect(img,color,xyrhw,lineW=1):
tl,tr,br,bl = getCorners(xyrhw)
cv2.line(img,tl,tr,color,lineW)
cv2.line(img,tr,br,color,lineW)
cv2.line(img,br,bl,color,lineW)
cv2.line(img,bl,tl,color,lineW)
示例7: collapse_RGB
# 需要導入模塊: import skimage [as 別名]
# 或者: from skimage import color [as 別名]
def collapse_RGB(self, image, name):
if len(image.shape) == 3:
if image.shape[2] == 1:
#print " this image (%s)\n is only one channel as of reaching process_image" % name
pass
elif image.shape[2] == 3:
#image = image.astype('uint8')
#img_show = PIL.Image.fromarray(image[...,0])
#img_show.save('./mastcam_images/%s_bandR.png' % name)
#img_show = PIL.Image.fromarray(image[...,1])
#img_show.save('./mastcam_images/%s_bandG.png' % name)
#img_show = PIL.Image.fromarray(image[...,2])
#img_show.save('./mastcam_images/%s_bandB.png' % name)
image = image.astype('uint16')
image = image[...,0] + image[...,1] + image[...,2]
image = image / 3
image = image.astype('uint8')
#img_show = PIL.Image.fromarray(image)
#img_show.save('./mastcam_images/%s_rgb.png' % name)
elif image.shape[2] == 7:
image = image.astype('uint16')
image = image[...,0] + image[...,1] + image[...,2] + image[...,3] + image[...,4] + image[...,5] + image[...,6]
image = image / 7
image = image.astype('uint8')
else:
print "This image has %d color bands and that's weird." % image.shape[2]
exit()
elif len(image.shape) == 2:
print "This image has only one channel!"
pass
else:
print "This image has %d dimensions and that's weird." % len(image.shape)
exit()
return image
#_______________________________________________________________________________
#_______________________________________main____________________________________
#