当前位置: 首页>>代码示例>>Python>>正文


Python color.gray2rgb方法代码示例

本文整理汇总了Python中skimage.color.gray2rgb方法的典型用法代码示例。如果您正苦于以下问题:Python color.gray2rgb方法的具体用法?Python color.gray2rgb怎么用?Python color.gray2rgb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.color的用法示例。


在下文中一共展示了color.gray2rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def load_image(path_image, force_rgb=True):
    """ load the image in value range (0, 1)

    :param str path_image: path to the image
    :param bool force_rgb: convert RGB image
    :return ndarray: np.array<height, width, ch>

    >>> img = np.random.random((50, 50))
    >>> save_image('./test_image.jpg', img)
    >>> img2 = load_image('./test_image.jpg')
    >>> img2.max() <= 1.
    True
    >>> os.remove('./test_image.jpg')
    """
    assert os.path.isfile(path_image), 'missing image "%s"' % path_image
    image = np.array(Image.open(path_image))
    while image.max() > 1.5:
        image = image / 255.
    if force_rgb and (image.ndim == 2 or image.shape[2] == 1):
        image = image[:, :, 0] if image.ndim == 3 else image
        image = gray2rgb(image)
    return image.astype(np.float32) 
开发者ID:Borda,项目名称:BIRL,代码行数:24,代码来源:data_io.py

示例2: output_blob_detection

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def output_blob_detection(self, img, blobs):
        colim = color.gray2rgb(img)
        
        for blob in blobs:
            x, y, r = blob
                        
            rr, cc = skimage.draw.circle(x,y,r)
            colorvalue = (255, 0, 0)
            
            if np.min(rr) < 0 or np.min(cc) < 0 or np.max(rr) >= img.shape[0]  or np.max(cc) >= img.shape[1]:
                continue
            
            for i, col in enumerate(colorvalue):
                colim[rr,cc,i] = col
 
        return colim 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:18,代码来源:segmentation_test.py

示例3: get_resized_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def get_resized_image(file, ratio):
    img = util.img_as_float(io.imread(file))
    if len(img.shape) >= 3 and img.shape[2] == 4:
        img = color.rgba2rgb(img)
    if len(img.shape) == 2:
        img = color.gray2rgb(img)

    eimg = filters.sobel(color.rgb2gray(img))
    width = img.shape[1]
    height = img.shape[0]

    mode, rm_paths = get_lines_to_remove((width, height), ratio)
    if mode:
        logger.debug("Carving %s %s paths ", rm_paths, mode)
        outh = transform.seam_carve(img, eimg, mode, rm_paths)
        return outh
    else:
        return img 
开发者ID:ftramer,项目名称:ad-versarial,代码行数:20,代码来源:generator.py

示例4: rgb2caffe

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def rgb2caffe(im, out_size=(128, 171)):
    '''
    Converts an RGB image to caffe format and downscales it as needed by C3D

    Parameters
    ----------
    im numpy array
        an RGB image
    downscale

    Returns
    -------
    a caffe image (channel,height, width) in BGR format

    '''
    im=np.copy(im)
    if len(im.shape)==2: # Make sure the image has 3 channels
        im = color.gray2rgb(im)

    h, w, _ = im.shape
    im = skimage.transform.resize(im, out_size, preserve_range=True)
    im = np.swapaxes(np.swapaxes(im, 1, 2), 0, 1)

    # Convert to BGR
    im = im[::-1, :, :]

    return np.array(im,theano.config.floatX) 
开发者ID:Lasagne,项目名称:Recipes,代码行数:29,代码来源:c3d.py

示例5: _normalise_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def _normalise_image(image, *, image_cmap=None):
    image = img_as_float(image)
    if image.ndim == 2:
        if image_cmap is None:
            image = gray2rgb(image)
        else:
            image = plt.get_cmap(image_cmap)(image)[..., :3]
    return image 
开发者ID:jni,项目名称:skan,代码行数:10,代码来源:draw.py

示例6: crop_boxes

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def crop_boxes(annos, types, img, context=0.0, draw_annotations=False):
    '''Crop a bounding boxes for TwoDAnnos from image.
    
    Args:
        annos (list): List of annotations.
        types (list): List of types.
        img (numpy.array): The image where boxes should be cropped from.
        context (float): The context that should be added to the box.
        draw_annotations (bool): If true, annotation will be painted inside
            the crop.
    
    Return:
        (list of numpy.array, list of list of float): 
            A tuple that contains a list of image crops and a 
            list of bboxes [[xc,yc,w,h],...]
    '''
    if annos:
        crops = []
        new_img = img
        anno_boxes = calc_box_for_anno(annos, types)
        boxes = trans_boxes_to(anno_boxes)
        if len(img.shape) < 3:
            img = gray2rgb(img)
        img_h, img_w, _ = img.shape
        boxes = to_abs(boxes, ['bbox']*len(boxes), (img_w,img_h))
        if context != 0.0:
            boxes = _add_context(boxes, context, (img_w, img_h))
        boxes = np.array(boxes, dtype=int).tolist()
        for idx, box in enumerate(boxes):
            if draw_annotations:
                new_img = img.copy()
                draw_annos([annos[idx]], [types[idx]], new_img)
            # image[y_min:y_max, x_min:x_max]
            crops.append(new_img[box[1]:box[3], box[0]:box[2]])
        return crops, anno_boxes
    else:
        return [], [] 
开发者ID:l3p-cv,项目名称:lost,代码行数:39,代码来源:anno_helper.py

示例7: my_label2rgboverlay

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def my_label2rgboverlay(labels, cmap, image, bglabel=None,
                        bg_color=(0., 0., 0.), alpha=0.2):
    '''Superimpose a mask over an image

    Convert a label mask to RGB applying a color map and superimposing it
    over an image as a transparent overlay'''
    image_float = gray2rgb(img_as_float(rgb2gray(image)))
    label_image = my_label2rgb(labels, cmap, bglabel=bglabel,
                               bg_color=bg_color)
    output = image_float * alpha + label_image * (1 - alpha)
    return output 
开发者ID:fvisin,项目名称:dataset_loaders,代码行数:13,代码来源:data_augmentation.py

示例8: overlay

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def overlay(self, img, imbin, contour=False):
        colim = color.gray2rgb(img)
        colorvalue = (0, 100, 200)
        if contour:
            se = morphology.diamond(2)
            ero = morphology.erosion(imbin, se)
            grad = imbin - ero
            colim[grad > 0] = colorvalue
        else:
            colim[imbin>0] = colorvalue
            
        return colim 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:14,代码来源:segmentation_test.py

示例9: use_rgb_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def use_rgb_image(img, clr='rgb'):
    # clr = params.get('clr_space', 'rgb').lower()
    if img.ndim == 3 and img.shape[-1] in (3, 4):
        img_rgb = tl_data.convert_img_color_to_rgb(img, clr)
    elif img.ndim == 2:
        img_rgb = sk_color.gray2rgb(img)
    else:
        img_rgb = img.copy()
    return img_rgb 
开发者ID:Borda,项目名称:pyImSegm,代码行数:11,代码来源:run_segm_slic_classif_graphcut.py

示例10: figure_used_samples

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def figure_used_samples(img, labels, slic, used_samples, fig_size=12):
    """ draw used examples (superpixels)

    :param ndarray img: input image for background
    :param list(int) labels: labels associated for superpixels
    :param ndarray slic: superpixel segmentation
    :param list(bool) used_samples: used samples for training
    :param int fig_size: figure size
    :return Figure:

    >>> img = np.random.random((50, 75, 3))
    >>> labels = [-1, 0, 2]
    >>> used = [1, 0, 0]
    >>> seg = np.random.randint(0, 3, img.shape[:2])
    >>> fig = figure_used_samples(img, labels, seg, used)
    >>> isinstance(fig, matplotlib.figure.Figure)
    True
    """
    w_samples = np.asarray(used_samples)[slic]
    img = color.gray2rgb(img) if img.ndim == 2 else img

    fig, axarr = create_figure_by_image(img.shape[:2], fig_size,
                                        nb_subfigs=2, extend=0.15)
    axarr[0].imshow(np.asarray(labels)[slic], cmap=plt.cm.jet)
    axarr[0].contour(slic, levels=np.unique(slic), colors='w', linewidths=0.5)
    axarr[0].axis('off')

    axarr[1].imshow(img)
    axarr[1].contour(slic, levels=np.unique(slic), colors='w', linewidths=0.5)
    cax = axarr[1].imshow(w_samples, cmap=plt.cm.RdYlGn, vmin=0, vmax=1, alpha=0.5)
    cbar = plt.colorbar(cax, ticks=[0, 1], boundaries=[-0.5, 0.5, 1.5])
    cbar.ax.set_yticklabels(['drop', 'used'])
    axarr[1].axis('off')

    fig.tight_layout()
    return fig 
开发者ID:Borda,项目名称:pyImSegm,代码行数:38,代码来源:drawing.py

示例11: __getitem__

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def __getitem__(self, idx):
		filename = self.root_dir + '/' + self.metas[idx][0]
		cls = self.metas[idx][1]
		img = io.imread(filename)
		img = color.gray2rgb(img)
		if self.transform:
			img = self.transform(img)
		return img, cls 
开发者ID:Cory-M,项目名称:DCCM,代码行数:10,代码来源:mc_dataset.py

示例12: _corrupt

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def _corrupt(self, source):
        """ corrupt the input with specific corruption method
            :param source: original data set
            :return: corrupted data set, if noise type is not defined, the original data set will return
        """
        if self.corrupt_type is None:
            return source
        noised = np.zeros((np.shape(source)[0],) + self.shape['in'])
        for i, raw in enumerate(source):
            if self.corrupt_type == 'GSN':
                noised[i] = random_noise(raw, 'gaussian', var=self.corrupt_ratio)
            elif self.corrupt_type == 'MSN':
                noised[i] = random_noise(raw, 'pepper', amount=self.corrupt_ratio)
            elif self.corrupt_type == 'SPN':
                noised[i] = random_noise(raw, 's&p', amount=self.corrupt_ratio)
            elif self.corrupt_type == 'GSB':
                noised[i] = gaussian(raw, sigma=self.corrupt_ratio, multichannel=True)
            elif self.corrupt_type == 'GRY':
                noised[i] = gray2rgb(rgb2gray(raw))
            elif self.corrupt_type == 'BLK':
                rad = int(self.corrupt_ratio)
                row = random.randint(rad, self.shape['in'][0] - rad - 1)
                col = random.randint(rad, self.shape['in'][1] - rad - 1)
                noised[i] = np.copy(raw)
                noised[i][circle(row, col, self.corrupt_ratio)] = 0
            elif self.corrupt_type == 'ZIP':
                noised[i] = rescale(raw, 0.5, mode='constant')
        return noised 
开发者ID:CongBao,项目名称:ImageEnhancer,代码行数:30,代码来源:enhancer_gan.py

示例13: l_to_rgb

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def l_to_rgb(img_l):
    """
    Convert a numpy array (l channel) into an rgb image
    :param img_l:
    :return:
    """
    lab = np.squeeze(255 * (img_l + 1) / 2)
    return color.gray2rgb(lab) / 255 
开发者ID:baldassarreFe,项目名称:deep-koalarization,代码行数:10,代码来源:training_utils.py

示例14: add_cross_to_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def add_cross_to_image(im, xx, yy):
    image = color.gray2rgb(im.copy())
    for h in range(-4, 5, 1):
        image[xx,yy+h] = (0, 1, 0)

    for v in range(-4, 5, 1):
        image[xx+v,yy] = (0, 1, 0)
    return image 
开发者ID:317070,项目名称:kaggle-heart,代码行数:10,代码来源:segmentation_labelling.py

示例15: convertseqVideo

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import gray2rgb [as 别名]
def convertseqVideo(videos,outtype='mp4',clahe=False,startF=None,endF=None):
    import os
    import io
    import cv2
    from tqdm import tqdm
    from PIL import Image
    from skimage import color
    from skimage.util import img_as_ubyte
    '''Convert videos to contrast adjusted videos of other formats'''
    ## get videos into a list in video folder
    videoDir = videos
    videolist = []
    for i in os.listdir(videoDir):
        if i.endswith('.seq'):
            videolist.append(os.path.join(videoDir,i))


    for video in videolist:
        vname = str(video)[:-4]
        f = open(video,'rb')
        info = readHeader(f)
        nframes = info.numFrames
        pos,frameSize = posFrame(f,nframes)
        fps=info.fps
        size = (info.width, info.height)
        extra=4
        if startF is None:
            startF=0
        if endF is None:
            endF=nframes
        if outtype=='avi':
            print('Coming soon')
        if outtype=='mp4':
            outname=os.path.join(vname + '.mp4')
            videowriter=cv2.VideoWriter(outname,cv2.VideoWriter_fourcc('m','p','4','v'),fps,size,isColor=True)
        for index in tqdm(range(startF,endF)):
            f.seek(pos[index]+extra*(index+1),0)
            imgdata=f.read(frameSize[index])
            image=Image.open(io.BytesIO(imgdata))
            image=img_as_ubyte(image)
            if clahe:
                image=cv2.createCLAHE(clipLimit=2,tileGridSize=(16,16)).apply(image)
            image=color.gray2rgb(image)
            frame=image
            videowriter.write(frame)
        f.close()
        videowriter.release()

    print('Finish conversion.') 
开发者ID:sgoldenlab,项目名称:simba,代码行数:51,代码来源:extract_seqframes.py


注:本文中的skimage.color.gray2rgb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。