• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.img_as_ubyte函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skimage.util.img_as_ubyte函数的典型用法代码示例。如果您正苦于以下问题:Python img_as_ubyte函数的具体用法?Python img_as_ubyte怎么用?Python img_as_ubyte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_tag_detections

def get_tag_detections(im):
    #
    # Because of a bug in the tag detector, it doesn't seem
    # to detect tags larger than a certain size. To work-around
    # this limitation, we detect tags on two different image
    # scales and use the one with more detections
    #
    assert len(im.shape) == 2
    im4 = imrescale(im, 1./4)

    im  = img_as_ubyte(im)
    im4 = img_as_ubyte(im4)

    detections1 = AprilTagDetector().detect(im)
    detections4 = AprilTagDetector().detect(im4)
    for d in detections4:
        d.c[0] *= 4.
        d.c[1] *= 4.

    # note that everything other than the tag center is wrong
    # in detections4

    if len(detections4) > len(detections1):
        return detections4
    else:
        return detections1
开发者ID:memorydump85,项目名称:zoomcalib,代码行数:26,代码来源:homography_at_center.py


示例2: insert_db

    def insert_db(self, mode, image, label, features, channel_no, inverse):
        if inverse:
            image_ubyte = 255 - img_as_ubyte(image)
        else:
            image_ubyte = img_as_ubyte(image)

        image_ubyte = numpy.transpose(image_ubyte, (2, 0, 1))
                
        image_string = image_ubyte.tostring()
        
        if features != None:
            delimeter = '[email protected]#$'
            self.datum.data = image_string + delimeter + features
        elif channel_no > 3:
            selem = disk(6)
            w_tophat = white_tophat(image_ubyte, selem)
            b_tophat = black_tophat(image_ubyte, selem)
            self.datum.data = image_string + w_tophat.tostring() + b_tophat.tostring()
        else:
            self.datum.data = image_string
            
        if label != None:
            self.datum.label = int(label)                
    
        serialized = self.datum.SerializeToString()
        
        if mode == 'train':
            self.train_batch.Put("%08d" % self.train_no, serialized)                    
            self.train_no += 1
        elif mode == 'valid':
            self.valid_batch.Put("%08d" % self.valid_no, serialized)                    
            self.valid_no += 1
        elif mode == 'test':
            self.test_batch.Put("%08d" % self.test_no, serialized)                    
            self.test_no += 1
开发者ID:only4hj,项目名称:fast-rcnn,代码行数:35,代码来源:convert_imagenet_data.py


示例3: mse

def mse(image_a, image_b):
    # the 'Mean Squared Error' between the two images is the
    # sum of the squared difference between the two images;
    # NOTE: the two images must have the same dimension
    image_a = util.img_as_ubyte(image_a)
    image_b = util.img_as_ubyte(image_b)
    err = np.sum((image_a.astype("float") - image_b.astype("float")) ** 2)
    err /= float(image_a.shape[0] * image_a.shape[1])
    
    # return the MSE, the lower the error, the more "similar"
    # the two images are
    return err
开发者ID:tomasra,项目名称:ga_sandbox,代码行数:12,代码来源:metrics.py


示例4: absolute_error

def absolute_error(image_a, image_b):
    """
    Sum of pixel differences
    Images - 2d numpy arrays
    """
    image_a = util.img_as_ubyte(image_a)
    image_b = util.img_as_ubyte(image_b)
    return np.sum(
        np.absolute(
            image_a.view(np.ndarray).astype(np.int16) -
            image_b.view(np.ndarray).astype(np.int16)
        )
    )
开发者ID:tomasra,项目名称:ga_sandbox,代码行数:13,代码来源:metrics.py


示例5: saver

    def saver(stepName, img, dbg=None, mode=mode):        
        path = (processedDir / str(imgName)).with_suffix(".{}.png".format(stepName) if stepName else ".png")
        
        if mode == 'cache' and processedDir and imgName:
            mode = 'save'
            if path.exists():
                print("Loading cached image:", path)
                img = ski.img_as_ubyte(io.imread(str(path)))
                mode = 'done'
            elif isinstance(img,type(None)):
                print("Caching image:", path)
                img = ski.img_as_ubyte(io.imread(str(imgName)))
            
        assert not isinstance(img,type(None))
        
        if mode == 'save' and processedDir and imgName:
            try:
                print("Saving:", img.shape, img.dtype, path.name, flush=True, )
                pil_img = PIL.Image.fromarray(img_as_ubyte(img))
                pil_img.save(str(path))
                if dbg:
                    dbg.saved_path = path
            except Exception as err:
                print("Error Saving:",path, err, flush=True, )

        elif mode == 'plot':
            plt.imshow(img)
            plt.suptitle(stepName+" "+imgName.name)
            plt.show(block=True)
            plt.close()

        return img
开发者ID:manasdas17,项目名称:scilab-2,代码行数:32,代码来源:image_measurements_auto.py


示例6: compute

    def compute(self, src):
        image = img_as_ubyte(src)

        # denoise image
        denoised = denoise_tv_chambolle(image, weight=0.05)
        denoised_equalize= exposure.equalize_hist(denoised)

        # find continuous region (low gradient) --> markers
        markers = rank.gradient(denoised_equalize, disk(5)) < 10
        markers = ndi.label(markers)[0]

        # local gradient
        gradient = rank.gradient(denoised, disk(2))

        # labels
        labels = watershed(gradient, markers)

        # display results
        fig, axes = plt.subplots(2,3)
        axes[0, 0].imshow(image)#, cmap=plt.cm.spectral, interpolation='nearest')
        axes[0, 1].imshow(denoised, cmap=plt.cm.spectral, interpolation='nearest')
        axes[0, 2].imshow(markers, cmap=plt.cm.spectral, interpolation='nearest')
        axes[1, 0].imshow(gradient, cmap=plt.cm.spectral, interpolation='nearest')
        axes[1, 1].imshow(labels, cmap=plt.cm.spectral, interpolation='nearest', alpha=.7)
        plt.show()
开发者ID:roboticslab-uc3m,项目名称:textiles,代码行数:25,代码来源:GarmentAnalysis.py


示例7: fit

 def fit(self, X, y=None):
     num = self.patch_num // X.size
     data = []
     for item in X:
         img = imread(str(item[0]))
         img = img_as_ubyte(rgb2gray(img))
         #img = self.binary(img) # 二值化
         tmp = extract_patches_2d(img, self.patch_size, max_patches = num,\
                                 random_state=np.random.RandomState())
         data.append(tmp)
     
     data = np.vstack(data)
     data = data.reshape(data.shape[0], -1)
     data = np.asarray(data, 'float32')
     
     # 二值化后不需要0-1归化
     data = data - np.min(data, 0)
     data = data/(np.max(data, 0) + 0.0001)  # 0-1 scaling
     
     self.rbm = BernoulliRBM(n_components=self.n_components,\
                     learning_rate=self.learning_rate, \
                     n_iter=self.n_iter,\
                     batch_size=self.batch_size,\
                     verbose=True)
     self.rbm.fit(data)
     return self
开发者ID:AI42,项目名称:CNN-detection-tracking,代码行数:26,代码来源:rbm.py


示例8: save_windows

def save_windows(boxes, imagePath):
    image_color = io.imread(imagePath, as_grey=False)
    image_color = util.img_as_ubyte(image_color)
    imageFilename = os.path.basename(imagePath) # Get the filename
    imageBasename = os.path.splitext(imageFilename)[0] #Take out the extension
    annotationsFilePath = cfg.annotationsFolderPath+'gt.'+imageBasename+'.txt'
    annotatedBoxes = utils.readINRIAAnnotations(annotationsFilePath)
    signalTypes = utils.readINRIAAnnotationsDetection(annotationsFilePath)
    signalTypes = list(reversed(signalTypes))
    count = 0
    for box in boxes:
        if box[0] < 0 or box[1] < 0:
            continue
        if box[2] >= image_color.shape[1].__int__() or \
                        box[3] >= image_color.shape[0].__int__():
            continue
        annotated = 'NONSIGNAL'
        for idx in range(0, len(annotatedBoxes)):
            aBox = annotatedBoxes[idx]
            currentRatio = computeOverlap(box, aBox)
            currentRatio = math.ceil(currentRatio*10)/10
            if currentRatio > 0.5:
                annotated = signalTypes[idx]
                break
        crop = image_color[box[1]:box[3],box[0]:box[2]]
        imageName = imagePath.split('/')  #Working on the crop name...
        fileName = imageName[len(imageName)-1]
        fileName = fileName[:len(fileName)-4]
        fileName = (fileName+'.'+str(count))
        filename = (fileName+'.'+annotated+'.jpg')
        crop = resize(crop,(32,32))
        io.imsave('Crops/'+filename, crop)  #Save the crop
        print('Crop saved')
        count += 1
开发者ID:axelBarroso,项目名称:m3,代码行数:34,代码来源:test_folder_parallel.py


示例9: extractAndStoreFeatures

def extractAndStoreFeatures(inputFolder, outputFolder):

    # List all files
    fileList = os.listdir(inputFolder)
    # Select only files that end with .png
    imagesList = filter(lambda element: ".png" in element, fileList)

    for filename in imagesList:
        imagepath = inputFolder + "/" + filename
        outputpath = outputFolder + "/" + filename + ".feat"

        if os.path.exists(outputpath):
            print "Features for " + imagepath + ". Delete the file if you want to replace."
            continue

        print "Extracting features for " + imagepath

        image = io.imread(imagepath, as_grey=True)
        # Read the image as bytes (pixels with values 0-255)
        image = util.img_as_ubyte(image)

        # Extract the features
        feats = feature_extractor.extractFeatures(image)

        # Save the features to a file
        outputFile = open(outputpath, "wb")
        pickle.dump(feats, outputFile)
        outputFile.close()
开发者ID:YoshuaNava,项目名称:VisionPercepcion_USB2015,代码行数:28,代码来源:extract_features.py


示例10: HairRemover

def HairRemover(image, debug=None):
    # =================================================================
    # extract hair as morphologically thin structures
    # -----------------------------------------------------------------

    # convert to Lab color space
    Lab_image = rgb2labnorm(image)
    L = img_as_ubyte(Lab_image[..., 0])

    # a hard threshold is then applied to the difference between
    # the luminance before and after morphological closing
    # the dark pigmented elements have a large intensity in the
    # difference image
    LClose = morph_close(L)
    LDiff = LClose - L

    # Threshold to create mask for inpainting
    # set all pixels > 11.9 -> 255 and < 12 -> 0
    # dilate by 1 to remove boundaries
    threshold = 10.0    # original comment and code did not match... -JH

    # threshold operation is directly performed on LDiff
    mask = (morph_dilate(LDiff) >= threshold) * 1.

    result = Inpainter(image, mask, 5)

    if debug is not None:
        debug["inpaintingMask"] = mask
        debug["hairRemoved"] = result
    
    return result
开发者ID:cmusatyalab,项目名称:dermshare,代码行数:31,代码来源:hairremover.py


示例11: test_compare_8bit_vs_16bit

def test_compare_8bit_vs_16bit():
    # filters applied on 8-bit image ore 16-bit image (having only real 8-bit
    # of dynamic) should be identical

    image8 = util.img_as_ubyte(data.camera())
    image16 = image8.astype(np.uint16)
    assert_equal(image8, image16)

    methods = [
        "autolevel",
        "bottomhat",
        "equalize",
        "gradient",
        "maximum",
        "mean",
        "subtract_mean",
        "median",
        "minimum",
        "modal",
        "enhance_contrast",
        "pop",
        "threshold",
        "tophat",
    ]

    for method in methods:
        func = getattr(rank, method)
        f8 = func(image8, disk(3))
        f16 = func(image16, disk(3))
        assert_equal(f8, f16)
开发者ID:YangChuan80,项目名称:scikit-image,代码行数:30,代码来源:test_rank.py


示例12: _write_to_file

    def _write_to_file(self, new_bands, pan, **kwargs):

        # Read coverage from QBA
        coverage = self._calculate_cloud_ice_perc()

        self.output("Final Steps", normal=True, arrow=True)

        suffix = 'bands_%s_pan' % "".join(map(str, self.bands))

        output_file = join(self.dst_path, self._filename(suffix=suffix))

        output = rasterio.open(output_file, 'w', **kwargs)

        for i, band in enumerate(new_bands):
            # Color Correction
            band = numpy.multiply(band, pan)
            band = self._color_correction(band, self.bands[i], 0, coverage)

            output.write_band(i + 1, img_as_ubyte(band))

            new_bands[i] = None

        self.output("Writing to file", normal=True, color='green', indent=1)

        return output_file
开发者ID:GEO-IASS,项目名称:landsat-util,代码行数:25,代码来源:image.py


示例13: extractAndStoreFeatures

def extractAndStoreFeatures(inputFolder, items, outputFolder):
	extension = '.jpg'
	X = np.zeros(shape=(cfg.num_train_images,cfg.num_features))
	y = np.zeros(shape=(cfg.num_train_images,1))
	number_of_images = 0
	for index_label, name_label in enumerate(items): # For each item...
		imagesPath = inputFolder + '/' + name_label # Each label corresponds to a folder
		fileList = os.listdir(imagesPath) # List all files
		imagesList = filter(lambda element: extension in element, fileList) # Select only the ones that ends with the desired extension
		for filename in imagesList:
			current_imagePath = imagesPath + '/' + filename
			print 'Extracting features for ' + current_imagePath
			image = io.imread(current_imagePath, as_grey=True)
			image = util.img_as_ubyte(image) # Read the image as bytes (pixels with values 0-255)
			X[number_of_images] = feature_extractor.extractFeatures(image) # Extract the features
			y[number_of_images] = index_label # Assign the label at the end of X when saving the data set
			number_of_images = number_of_images + 1
	print number_of_images
            
	#Save the data set to .data file in Data folder.
	np.savetxt(
	outputFolder,   		# file name
	np.c_[X,y],             # array to save
	fmt='%.2f',             # formatting, 2 digits in this case
	delimiter=',',          # column delimiter
	newline='\n',           # new line character  
	comments='# ')          # character to use for comments
开发者ID:GerardMJuan,项目名称:MCV-M3,代码行数:27,代码来源:extract_features.py


示例14: convert_to_saturation

def convert_to_saturation(fn, out_fn, rescale=True):
    """
    Generate saturation channel as a grayscale image.
    """

# ImageMagick 18s
#     execute_command('convert %(fn)s -colorspace HSL -channel G %(out_fn)s' % {'fn': fn, 'out_fn': out_fn})

#     t = time.time()
    img = imread(fn)
#     sys.stderr.write('Read image: %.2f seconds\n' % (time.time() - t)) # ~4s

#     t1 = time.time()
    ma = img.max(axis=-1)
    mi = img.min(axis=-1)
#     sys.stderr.write('compute min and max color components: %.2f seconds\n' % (time.time() - t1)) # ~5s

#     t1 = time.time()
    s = np.nan_to_num(mi/ma.astype(np.float))
#     sys.stderr.write('min oiver max: %.2f seconds\n' % (time.time() - t1)) # ~2s

#     t1 = time.time()
    if rescale:
        pmax = s.max()
        pmin = s.min()
        s = (s - pmin) / (pmax - pmin)
#     sys.stderr.write('rescale: %.2f seconds\n' % (time.time() - t1)) # ~3s

#     t1 = time.time()
    cv2.imwrite(out_fn, img_as_ubyte(s))
开发者ID:mistycheney,项目名称:MouseBrainAtlas,代码行数:30,代码来源:generate_other_versions_v2.py


示例15: _write_to_file

    def _write_to_file(self, new_bands, suffix=None, **kwargs):

        # Read cloud coverage from mtl file
        cloud_cover = self._read_cloud_cover()

        self.output("Final Steps", normal=True, arrow=True)

        output_file = '%s_bands_%s' % (self.scene, "".join(map(str, self.bands)))

        if suffix:
            output_file += suffix

        output_file += '.TIF'
        output_file = join(self.dst_path, output_file)

        output = rasterio.open(output_file, 'w', **kwargs)

        for i, band in enumerate(new_bands):
            # Color Correction
            band = self._color_correction(band, self.bands[i], 0, cloud_cover)

            output.write_band(i+1, img_as_ubyte(band))

            new_bands[i] = None
        self.output("Writing to file", normal=True, color='green', indent=1)

        return output_file
开发者ID:rcdosado,项目名称:landsat-util,代码行数:27,代码来源:image.py


示例16: ndarray_to_pil

def ndarray_to_pil(arr, format_str=None):
    """Export an ndarray to a PIL object.

    Parameters
    ----------
    Refer to ``imsave``.

    """
    if arr.ndim == 3:
        arr = img_as_ubyte(arr)
        mode = {3: 'RGB', 4: 'RGBA'}[arr.shape[2]]

    elif format_str in ['png', 'PNG']:
        mode = 'I;16'
        mode_base = 'I'

        if arr.dtype.kind == 'f':
            arr = img_as_uint(arr)

        elif arr.max() < 256 and arr.min() >= 0:
            arr = arr.astype(np.uint8)
            mode = mode_base = 'L'

        else:
            arr = img_as_uint(arr)

    else:
        arr = img_as_ubyte(arr)
        mode = 'L'
        mode_base = 'L'

    if arr.ndim == 2:
        im = Image.new(mode_base, arr.T.shape)
        try:
            im.frombytes(arr.tobytes(), 'raw', mode)
        except AttributeError:
            im.frombytes(arr.tostring(), 'raw', mode)

    else:
        try:
            im = Image.frombytes(mode, (arr.shape[1], arr.shape[0]),
                                 arr.tobytes())
        except AttributeError:
            im = Image.frombytes(mode, (arr.shape[1], arr.shape[0]),
                                  arr.tostring())
    return im
开发者ID:haohao200609,项目名称:Hybrid,代码行数:46,代码来源:pil_plugin.py


示例17: prepare_for_display

def prepare_for_display(npy_img):
    '''Convert a 2D or 3D numpy array of any dtype into a
    3D numpy array with dtype uint8. This array will
    be suitable for use in passing to gui toolkits for
    image display purposes.

    Parameters
    ----------
    npy_img : ndarray, 2D or 3D
        The image to convert for display

    Returns
    -------
    out : ndarray, 3D dtype=np.uint8
        The converted image. This is guaranteed to be a contiguous array.

    Notes
    -----
    If the input image is floating point, it is assumed that the data
    is in the range of 0.0 - 1.0. No check is made to assert this
    condition. The image is then scaled to be in the range 0 - 255
    and then cast to np.uint8

    For all other dtypes, the array is simply cast to np.uint8

    If a 2D array is passed, the single channel is replicated
    to the 2nd and 3rd channels.

    If the array contains an alpha channel, this channel is
    ignored.

    '''
    if npy_img.ndim < 2:
        raise ValueError('Image must be 2D or 3D array')

    height = npy_img.shape[0]
    width = npy_img.shape[1]

    out = np.empty((height, width, 3), dtype=np.uint8)
    npy_img = img_as_ubyte(npy_img)

    if npy_img.ndim == 2 or \
       (npy_img.ndim == 3 and npy_img.shape[2] == 1):
        npy_plane = npy_img.reshape((height, width))
        out[:, :, 0] = npy_plane
        out[:, :, 1] = npy_plane
        out[:, :, 2] = npy_plane

    elif npy_img.ndim == 3:
        if npy_img.shape[2] == 3 or npy_img.shape[2] == 4:
            out[:, :, :3] = npy_img[:, :, :3]
        else:
            raise ValueError('Image must have 1, 3, or 4 channels')

    else:
        raise ValueError('Image must have 2 or 3 dimensions')

    return out
开发者ID:ChrisBeaumont,项目名称:scikit-image,代码行数:58,代码来源:util.py


示例18: inplace_augment

def inplace_augment(data, outdir, fold=1, tparams=None, reset=False):
    output_json = osp.join(outdir, 'inplace_augment/data.json')
    if not os.path.exists(output_json) or reset:
        
        od = osp.join(outdir, 'inplace_augment')
        if not osp.exists(od):
            os.makedirs(od)
        
        if tparams == None:
            tparams = {}
            tparams['samples_per_image'] = 5
            tparams['shear'] = (-5, 30)
            tparams['order'] = 1            #bilinear
            tparams['selem_size'] = (3, 4)  #max size for square selem for erosion, dilation
            
        tparams['rotate'] = (0, 1)
        tparams['hpad'] = (0, 1)
        tparams['vpad'] = (0, 1)
            
        augmented = []
        for datum in data:
            dat = copy.deepcopy(datum)
            augmented.append(dat)

            if datum['split'] == 'train':
                datum['region_proposals'] = datum['gt_boxes'][:2] #smaller memory footprint, needed
                path, f = osp.split(datum['id'])
                for i in range(tparams['samples_per_image']):
                    img = imread(datum['id'])
                    if img.ndim == 3:
                        img = img_as_ubyte(rgb2gray(img))
                        
                    out = img.copy()
                    boxes = datum['gt_boxes']
                    for jj, b in enumerate(reversed(boxes)):
                        try: #Some random values for weird boxes give value errors, just handle and ignore
                            b = close_crop_box(img, b)
                            word = img[b[1]:b[3], b[0]:b[2]]
                            aug = augment(word, tparams, keep_size=True)
                        except ValueError:
                            continue
                            
                        out[b[1]:b[3], b[0]:b[2]] = aug
                    
                    new_path = osp.join(od, f[:-4] + '_%d.png' % i)
                    imsave(new_path, out)
                    new_datum = copy.deepcopy(datum)
                    new_datum['id'] = new_path
                    augmented.append(new_datum)
                
        with open(output_json, 'w') as f:
            json.dump(augmented, f)
    
    else: #otherwise load the json
        with open(output_json) as f:
            augmented = json.load(f) 
            
    return augmented
开发者ID:tomfalainen,项目名称:neural-ctrlf,代码行数:58,代码来源:dataset_loader.py


示例19: get_gabor_desc

def get_gabor_desc(img, gdesc, w_size, scale=1.0, mask=None, _ncpus=None):
    """
    Extract local Gabor descriptors by scanning an image.

    :param img: numpy.ndarray
      Input intensity (grey-scale) image.

    :param gdesc: txtgrey.GaborDescriptor
      The parameters of the Gabor wavelets to be used.

    :param w_size: integer
      Window size (the sliding window is square-shaped).

    :param scale: float
      The image may be scaled prior to any descriptor extraction.

    :param mask: numpy.ndarray
      A mask (logical image) indicating the object regions
      in the image.

    :return: list
      A list with the local descriptors corresponding to each position
      of the sliding window. Each element of the list is a vector
      containing the coordinates of the local window (first 4 elements)
      and the 2 vectors of values for the local Gabor descriptors (one
      with the mean responses and one with the variances).
    """

    assert (img.ndim == 2)

    img_ = rescale(img, scale)
    if mask is not None:
        assert (mask.ndim == 2)
        assert (mask.shape == img.shape)
        mask = img_as_ubyte(resize(mask, img_.shape))

    img_iterator = sliding_window(img_.shape, (w_size, w_size), step=(w_size, w_size))  # non-overlapping windows

    res = []
    if mask is None:
        with ProcessPoolExecutor(max_workers=_ncpus) as executor:
            for w_coords in img_iterator:
                time.sleep(0.01)
                res.append(executor.submit(_gabor_worker, img_, gdesc, w_coords))
    else:
        th = w_size * w_size / 20.0   # consider only those windows with more than 5% pixels from object
        with ProcessPoolExecutor(max_workers=_ncpus) as executor:
            for w_coords in img_iterator:
                time.sleep(0.01)
                if mask[w_coords[0]:w_coords[1], w_coords[2]:w_coords[3]].sum() > th:
                    res.append(executor.submit(_gabor_worker, img_, gdesc, w_coords))

    desc = []
    for f in as_completed(res):
        desc.append(f.result())

    return desc
开发者ID:gitter-badger,项目名称:WSItk,代码行数:57,代码来源:extract.py


示例20: punchhole_removal

def punchhole_removal(im):
    import numpy as np
    from PIL import Image
    from skimage import io
    from skimage.color import rgba2rgb, rgb2gray
    from skimage.transform import hough_circle, hough_circle_peaks
    from skimage.feature import canny
    from skimage.draw import circle
    from skimage.util import img_as_ubyte

    ''' check for punch holes and remove  '''
    
    max_peaks =  24 #maximum number of peaks to be found. changed from 99 to 24 for reducing the unnecessary punch holes being filled.

    img = np.array(im)# Load picture .
    img_rgb = rgba2rgb(img)# convert to RGB
    img_gray = rgb2gray(img_rgb)# convert to gray
    image = img_as_ubyte(img_gray)
    width, height = image.shape
    x1 =  punchhole_margin
    x2 =  (int)(width - punchhole_margin)
    y1 =  (int)(height - punchhole_margin)
    y2 =  punchhole_margin

    edges = canny(image, 3, 10, 40) # perform canny to detect the edges
    hough_radii = np.arange(31, 34, 1) #get the radius range with step as 1.
    hough_res = hough_circle(edges, hough_radii) # detect the circles centres coordinates

    # Select the most prominent circles based on the max_peaks
    accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,total_num_peaks=max_peaks)

    for center_y, center_x, radius in zip(cy, cx, radii):

        #if the circles centres fall in the border regions, 
        #get the dominant color near the hole and fill the hole with a linear gradient of the dominant color
        if(((0 < center_y < width) and (0 < center_x < y2)) or \
           ((0 < center_y < width) and (y1 < center_x < height)) or\
           ((0 < center_y < x1) and (0 < center_x < height)) or \
           ((x2 < center_y < width) and (0 < center_x < height))):

            index=0
            rr, cc= circle(center_y, center_x, radius+1, img.shape)
            dominantpix = dominantcolor(center_x, center_y, radius, img)           
            dark_grad = [dominantpix[0], dominantpix[1],dominantpix[2]]
            light_grad = [dominantpix[0]+1, dominantpix[1]+1, dominantpix[2]+1]
            #white_grad = [255,255,255]
            RGBA_list = lineargradient(dark_grad,light_grad,len(list(rr)))   
          
            for i , j in zip(list(rr), list(cc)):
                pixlist = RGBA_list[index]
                pixtuple = tuple(pixlist)
                img[i,j]= (pixtuple[0], pixtuple[1], pixtuple[2], 255)
                index += 1
           
    finalimage=Image.fromarray(img)

    return finalimage
开发者ID:zdohnal,项目名称:hplip,代码行数:57,代码来源:imageprocessing.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.pad函数代码示例发布时间:2022-05-27
下一篇:
Python util.img_as_float函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap