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

Python skimage.img_as_uint函数代码示例

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

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



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

示例1: RQA_eval

def RQA_eval(x_in, TR, RPpow, img_process):

    RQA_mat_L = zeros((TR, TR))

    # Set L,R matrix to compute Recurrence matrix
    RQA_mat_L[0:TR, :] = x_in
    RQA_mat_R = RQA_mat_L.transpose()

    if img_process == -1:

        # Subtract two matirices
        RQA_value = RQA_mat_L - RQA_mat_R

    if img_process == 0:

        # RQA_value = RQA_value/amax(abs(RQA_value))
        # Subtract two matirices
        RQA_value = abs(RQA_mat_L - RQA_mat_R)
        RQA_value = RQA_value ** RPpow

    if img_process == 1:

        # RQA_value = RQA_value/amax(abs(RQA_value))
        RQA_value = img_as_uint(RQA_value)
        RQA_value = skimage.exposure.equalize_hist(RQA_value)

    if img_process == 2:

        # RQA_value = RQA_value/amax(abs(RQA_value))
        RQA_value = img_as_uint(RQA_value)
        RQA_value = skimage.exposure.equalize_adapthist(RQA_value, clip_limit=0.01)

    RQA_value -= mean(RQA_value)

    return RQA_value
开发者ID:kelelexu,项目名称:music-noise-segmentation-on-a-spectrogram,代码行数:35,代码来源:RQA_func_det2.py


示例2: mono_check

def mono_check(plugin, fmt='png'):
    """Check the roundtrip behavior for images that support most types.

    All major input types should be handled.
    """

    img = img_as_ubyte(data.moon())
    r1 = roundtrip(img, plugin, fmt)
    testing.assert_allclose(img, r1)

    img2 = img > 128
    r2 = roundtrip(img2, plugin, fmt)
    testing.assert_allclose(img2.astype(np.uint8), r2)

    img3 = img_as_float(img)
    r3 = roundtrip(img3, plugin, fmt)
    if r3.dtype.kind == 'f':
        testing.assert_allclose(img3, r3)
    else:
        testing.assert_allclose(r3, img_as_uint(img))

    img4 = img_as_int(img)
    if fmt.lower() in (('tif', 'tiff')):
        img4 -= 100
        r4 = roundtrip(img4, plugin, fmt)
        testing.assert_allclose(r4, img4)
    else:
        r4 = roundtrip(img4, plugin, fmt)
        testing.assert_allclose(r4, img_as_uint(img4))

    img5 = img_as_uint(img)
    r5 = roundtrip(img5, plugin, fmt)
    testing.assert_allclose(r5, img5)
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:33,代码来源:testing.py


示例3: equalize_adapthist

def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
                       nbins=256):
    """Contrast Limited Adaptive Histogram Equalization.

    Parameters
    ----------
    image : array-like
        Input image.
    ntiles_x : int, optional
        Number of tile regions in the X direction.  Ranges between 2 and 16.
    ntiles_y : int, optional
        Number of tile regions in the Y direction.  Ranges between 2 and 16.
    clip_limit : float: optional
        Clipping limit, normalized between 0 and 1 (higher values give more
        contrast).
    nbins : int, optional
        Number of gray bins for histogram ("dynamic range").

    Returns
    -------
    out : ndarray
        Equalized image.

    Notes
    -----
    * The algorithm relies on an image whose rows and columns are even
      multiples of the number of tiles, so the extra rows and columns are left
      at their original values, thus  preserving the input image shape.
    * For color images, the following steps are performed:
       - The image is converted to LAB color space
       - The CLAHE algorithm is run on the L channel
       - The image is converted back to RGB space and returned
    * For RGBA images, the original alpha channel is removed.

    References
    ----------
    .. [1] http://tog.acm.org/resources/GraphicsGems/gems.html#gemsvi
    .. [2] https://en.wikipedia.org/wiki/CLAHE#CLAHE
    """
    args = [None, ntiles_x, ntiles_y, clip_limit * nbins, nbins]
    if image.ndim > 2:
        lab_img = color.rgb2lab(skimage.img_as_float(image))
        l_chan = lab_img[:, :, 0]
        l_chan /= np.max(np.abs(l_chan))
        l_chan = skimage.img_as_uint(l_chan)
        args[0] = rescale_intensity(l_chan, out_range=(0, NR_OF_GREY - 1))
        new_l = _clahe(*args).astype(float)
        new_l = rescale_intensity(new_l, out_range=(0, 100))
        lab_img[:new_l.shape[0], :new_l.shape[1], 0] = new_l
        image = color.lab2rgb(lab_img)
        image = rescale_intensity(image, out_range=(0, 1))
    else:
        image = skimage.img_as_uint(image)
        args[0] = rescale_intensity(image, out_range=(0, NR_OF_GREY - 1))
        out = _clahe(*args)
        image[:out.shape[0], :out.shape[1]] = out
        image = rescale_intensity(image)
    return image
开发者ID:4rozenwolves,项目名称:scikit-image,代码行数:58,代码来源:_adapthist.py


示例4: test_tv_denoise_2d

 def test_tv_denoise_2d(self):
     """
     Apply the TV denoising algorithm on the lena image provided
     by scipy
     """
     # lena image
     lena = color.rgb2gray(data.lena())[:256, :256]
     # add noise to lena
     lena += 0.5 * lena.std() * np.random.randn(*lena.shape)
     # clip noise so that it does not exceed allowed range for float images.
     lena = np.clip(lena, 0, 1)
     # denoise
     denoised_lena = filter.tv_denoise(lena, weight=60.0)
     # which dtype?
     assert denoised_lena.dtype in [np.float, np.float32, np.float64]
     from scipy import ndimage
     grad = ndimage.morphological_gradient(lena, size=((3, 3)))
     grad_denoised = ndimage.morphological_gradient(
         denoised_lena, size=((3, 3)))
     # test if the total variation has decreased
     assert np.sqrt(
         (grad_denoised ** 2).sum()) < np.sqrt((grad ** 2).sum()) / 2
     denoised_lena_int = filter.tv_denoise(img_as_uint(lena),
                                           weight=60.0, keep_type=True)
     assert denoised_lena_int.dtype is np.dtype('uint16')
开发者ID:amueller,项目名称:scikit-image,代码行数:25,代码来源:test_tv_denoise.py


示例5: saveRegion

    def saveRegion(self):
        imageBaseName = os.path.basename(
            self.regionImage.fileName).split('.')[0]
        pathToSave = os.path.join(workDir, imageBaseName)
        for c, arr in self.imagesArrays.iteritems():
            io.imsave(os.path.join(pathToSave,
                                   '_'.join((
                                       self._type,
                                       str(self.timeStamp),
                                       c, imageBaseName+'.tif'))),
                      img_as_uint(arr))
        if self.contour is not None:
            np.savetxt(os.path.join(pathToSave,
                                    '_'.join((self._type,
                                              str(self.timeStamp),
                                              'contour.dat'))), self.contour)
        np.savetxt(os.path.join(pathToSave,
                                '_'.join((self._type,
                                          str(self.timeStamp),
                                          'mask.dat'))), self.mask)
        # pickle.dump(self.metaData,
        #            open(os.path.join(pathToSave, 'metaData.dat'), 'wb'))
        writer = csv.writer(open(os.path.join(pathToSave,
                                              '_'.join((self._type,
                                                       str(self.timeStamp),
                                                       'metaData.dat'))),
                                 'wb'), delimiter=':')

        self.sortedmetaData = collections.OrderedDict(sorted(
            self.metaData.items()))
        for k, v in self.sortedmetaData.iteritems():
            writer.writerow([k, v])
开发者ID:MichalZG,项目名称:cellROI,代码行数:32,代码来源:cellroi.py


示例6: _write_movie_frame

    def _write_movie_frame(frame, base_path, image_filename):
        """
        Takes a movie frame, adds the frame number to the bottom right of the image, and saves it to disk.

        """
        # We have to set up a Matplotlib plot so we can add text.
        # scikit-image unfortunately has no text annotation methods.
        # fig, ax = plt.subplots()
        # ax.imshow(frame, cmap=cm.gray)
        #
        # # Remove whitespace and ticks from the image, since we're making a movie, not a plot.
        # # Matplotlib is expecting us to make a plot though, so removing all evidence of this is tricky.
        # plt.gca().set_axis_off()
        # plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
        # plt.margins(0, 0)
        # plt.gca().xaxis.set_major_locator(plt.NullLocator())
        # plt.gca().yaxis.set_major_locator(plt.NullLocator())

        # Add the frame number to the bottom right of the image in red text
        # ax.annotate(str(frame_number + 1), xy=(1, 1), xytext=(frame.shape[1] - 9, frame.shape[0] - 5), color='r')
        log.info("Creating %s" % base_path + "/" + image_filename)
        # Write the frame to disk
        # fig.savefig(base_path + "/" + image_filename, bbox_inches='tight', pad_inches=0)
        # Closing the plot is required or memory goes nuts
        # plt.close()
        img = img_as_uint(frame)
        skimage.io.imsave(base_path + "/" + image_filename, img, plugin='freeimage')
开发者ID:finkelsteinlab,项目名称:fylm,代码行数:27,代码来源:movie.py


示例7: main

def main():
	args = vars(parser.parse_args())
	filename = os.path.join(os.getcwd(), args["image"][0])

	image = skimage.img_as_uint(color.rgb2gray(io.imread(filename)))

	subsample = 1

	if (not args["subsample"] == 1):
		subsample = args["subsample"][0]

		image = transform.downscale_local_mean(image, (subsample, subsample))
		image = transform.pyramid_expand(image, subsample, 0, 0)

	image = exposure.rescale_intensity(image, out_range=(0,args["depth"][0]))

	if (args["visualize"]):
		io.imshow(image)
		io.show()

	source = generate_face(image, subsample, args["depth"][0], FLICKER_SPEED)

	if source:
		with open(args["output"][0], 'w') as file_:
			file_.write(source)
	else:
		print "Attempted to generate source code, failed."
开发者ID:kctess5,项目名称:sad_robot,代码行数:27,代码来源:main.py


示例8: __convert_type

 def __convert_type(array):
     if im_type in (np.int16, np.uint16):
         return img_as_uint(array)
     elif im_type in (np.int8, np.uint8):
         return img_as_ubyte(array)
     else:
         return array
开发者ID:amaxwell,项目名称:datatank_py,代码行数:7,代码来源:DTBitmap2D.py


示例9: run

    def run(self, workspace):
        x_name = self.x_name.value

        y_name = self.y_name.value

        images = workspace.image_set

        x = images.get_image(x_name)

        x_data = x.pixel_data

        x_data = skimage.img_as_uint(x_data)

        if x.dimensions == 3 or x.multichannel:
            y_data = numpy.zeros_like(x_data)

            for z, image in enumerate(x_data):
                y_data[z] = skimage.filters.rank.gradient(image, self.__structuring_element())
        else:
            y_data = skimage.filters.rank.gradient(x_data, self.structuring_element.value)

        y = cellprofiler.image.Image(
            image=y_data,
            dimensions=x.dimensions,
            parent_image=x,
        )

        images.add(y_name, y)

        if self.show_window:
            workspace.display_data.x_data = x_data

            workspace.display_data.y_data = y_data

            workspace.display_data.dimensions = x.dimensions
开发者ID:zindy,项目名称:CellProfiler,代码行数:35,代码来源:imagegradient.py


示例10: imSave

def imSave(img, filename, range='float'):
    f = open(filename,'wb')
    w = png.Writer(313, 443, greyscale=True, bitdepth=8)
    img_w = exposure.rescale_intensity(img,out_range=range)
    img_w = img_as_uint(img_w)
    w.write(f, img_w)
    f.close()
开发者ID:Crobisaur,项目名称:HyperSpec,代码行数:7,代码来源:hs_imFFTW.py


示例11: test_save_buttons

def test_save_buttons():
    viewer = get_image_viewer()
    sv = SaveButtons()
    viewer.plugins[0] += sv

    import tempfile
    fid, filename = tempfile.mkstemp(suffix='.png')
    os.close(fid)

    timer = QtCore.QTimer()
    timer.singleShot(100, QtGui.QApplication.quit)

    # exercise the button clicks
    sv.save_stack.click()
    sv.save_file.click()

    # call the save functions directly
    sv.save_to_stack()
    with expected_warnings(['precision loss']):
        sv.save_to_file(filename)

    img = data.imread(filename)

    with expected_warnings(['precision loss']):
        assert_almost_equal(img, img_as_uint(viewer.image))

    img = io.pop()
    assert_almost_equal(img, viewer.image)

    os.remove(filename)
开发者ID:AbdealiJK,项目名称:scikit-image,代码行数:30,代码来源:test_widgets.py


示例12: test_save_im_colour_16bit

def test_save_im_colour_16bit():
    im = np.random.uniform(size=(256, 256, 3))
    im = img_as_uint(im)
    fname = os.path.join('tests', 'test_data', 'tmp.png')
    pu.image.save_im(fname, im, bitdepth=16)
    im2 = io.imread(fname)
    assert im.all() == im2.all()
开发者ID:tomwallis,项目名称:PsyUtils,代码行数:7,代码来源:image_utils_tests.py


示例13: color_check

def color_check(plugin, fmt='png'):
    """Check roundtrip behavior for color images.

    All major input types should be handled as ubytes and read
    back correctly.
    """
    img = img_as_ubyte(data.chelsea())
    r1 = roundtrip(img, plugin, fmt)
    testing.assert_allclose(img, r1)

    img2 = img > 128
    r2 = roundtrip(img2, plugin, fmt)
    testing.assert_allclose(img2.astype(np.uint8), r2)

    img3 = img_as_float(img)
    r3 = roundtrip(img3, plugin, fmt)
    testing.assert_allclose(r3, img)

    img4 = img_as_int(img)
    if fmt.lower() in (('tif', 'tiff')):
        img4 -= 100
        r4 = roundtrip(img4, plugin, fmt)
        testing.assert_allclose(r4, img4)
    else:
        r4 = roundtrip(img4, plugin, fmt)
        testing.assert_allclose(r4, img_as_ubyte(img4))

    img5 = img_as_uint(img)
    r5 = roundtrip(img5, plugin, fmt)
    testing.assert_allclose(r5, img)
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:30,代码来源:testing.py


示例14: _apply

def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y):
    selem = img_as_ubyte(selem > 0)
    image = np.ascontiguousarray(image)

    if mask is None:
        mask = np.ones(image.shape, dtype=np.uint8)
    else:
        mask = np.ascontiguousarray(mask)
        mask = img_as_ubyte(mask)

    if image is out:
        raise NotImplementedError("Cannot perform rank operation in place.")

    is_8bit = image.dtype in (np.uint8, np.int8)

    if func8 is not None and (is_8bit or func16 is None):
        out = _apply8(func8, image, selem, out, mask, shift_x, shift_y)
    else:
        image = img_as_uint(image)
        if out is None:
            out = np.zeros(image.shape, dtype=np.uint16)
        bitdepth = find_bitdepth(image)
        if bitdepth > 11:
            image = image >> 4
            bitdepth = find_bitdepth(image)
        func16(image, selem, shift_x=shift_x, shift_y=shift_y, mask=mask,
               bitdepth=bitdepth + 1, out=out)

    return out
开发者ID:RONNCC,项目名称:scikit-image,代码行数:29,代码来源:_rank.py


示例15: guess_corners

def guess_corners(bw):
    """
    Infer the corners of an image using a Sobel filter to find the edges and a
    Harris filter to find the corners.  Takes only as single color chanel.

    Parameters
    ----------
    bw : (m x n) ndarray of ints

    Returns
    -------
    corners : pixel coordinates of plot corners, unsorted
    outline : (m x n) ndarray of bools True -> plot area
    """
    assert len(bw.shape) == 2
    bw = img_as_uint(bw)
    e_map = ndimage.sobel(bw)

    markers = np.zeros(bw.shape, dtype=int)
    markers[bw < 30] = 1
    markers[bw > 150] = 2
    seg = ndimage.watershed_ift(e_map, np.asarray(markers, dtype=int))

    outline = ndimage.binary_fill_holes(1 - seg)
    corners = harris(np.asarray(outline, dtype=int))
    corners = approximate_polygon(corners, 1)
    return corners, outline
开发者ID:waltherg,项目名称:yoink,代码行数:27,代码来源:guess.py


示例16: equalize_adapthist

def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
                       nbins=256):
    args = [None, ntiles_x, ntiles_y, clip_limit * nbins, nbins]
    image = skimage.img_as_uint(image)
    args[0] = rescale_intensity(image, out_range=(0, NR_OF_GREY - 1))
    out = _clahe(*args)
    image[:out.shape[0], :out.shape[1]] = out
    image = rescale_intensity(image)
    return image
开发者ID:karthik,项目名称:scikitimage,代码行数:9,代码来源:Pre-Process_Full.py


示例17: getImageContours

    def getImageContours(self, gray):
        ret, thresh = cv2.threshold(gray, 220, 255, cv2.THRESH_TOZERO)
        fill = ndimage.binary_fill_holes(thresh)

        clean = morphology.remove_small_objects(fill, 12)
        clean = img_as_uint(clean).astype(np.dtype('uint8'))
        contour_image = clean.copy()

        contours, hierarchy = cv2.findContours(contour_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_TC89_KCOS)
        return contours
开发者ID:jtreleaven,项目名称:opc_application,代码行数:10,代码来源:ObjectClassifier.py


示例18: equalize_adapthist

def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
                       nbins=256):
    """Contrast Limited Adaptive Histogram Equalization (CLAHE).

    An algorithm for local contrast enhancement, that uses histograms computed
    over different tile regions of the image. Local details can therefore be
    enhanced even in regions that are darker or lighter than most of the image.

    Parameters
    ----------
    image : array-like
        Input image.
    ntiles_x : int, optional
        Number of tile regions in the X direction.  Ranges between 1 and 16.
    ntiles_y : int, optional
        Number of tile regions in the Y direction.  Ranges between 1 and 16.
    clip_limit : float: optional
        Clipping limit, normalized between 0 and 1 (higher values give more
        contrast).
    nbins : int, optional
        Number of gray bins for histogram ("dynamic range").

    Returns
    -------
    out : ndarray
        Equalized image.

    See Also
    --------
    equalize_hist, rescale_intensity

    Notes
    -----
    * For color images, the following steps are performed:
       - The image is converted to HSV color space
       - The CLAHE algorithm is run on the V (Value) channel
       - The image is converted back to RGB space and returned
    * For RGBA images, the original alpha channel is removed.
    * The CLAHE algorithm relies on image blocks of equal size.  This may
      result in extra border pixels that would not be handled.  In that case,
      we pad the image with a repeat of the border pixels, apply the
      algorithm, and then trim the image to original size.

    References
    ----------
    .. [1] http://tog.acm.org/resources/GraphicsGems/gems.html#gemsvi
    .. [2] https://en.wikipedia.org/wiki/CLAHE#CLAHE
    """
    image = skimage.img_as_uint(image)
    image = rescale_intensity(image, out_range=(0, NR_OF_GREY - 1))
    out = _clahe(image, ntiles_x, ntiles_y, clip_limit * nbins, nbins)
    image[:out.shape[0], :out.shape[1]] = out
    image = skimage.img_as_float(image)
    return rescale_intensity(image)
开发者ID:JeanKossaifi,项目名称:scikit-image,代码行数:54,代码来源:_adapthist.py


示例19: temp_filter_method_adaptive_thresholding

def temp_filter_method_adaptive_thresholding(imageFile):
    img = data.imread(imageFile, as_grey=True)

    global_thresh = threshold_yen(img)
    # True False binary matrix represent color value of the img using global thresholding
    binary_global = img > global_thresh

    block_size = 40

    # True False binary matrix represent color value of the img using adaptive thresholding
    binary_adaptive = threshold_adaptive(img, block_size, offset=0)

    # 0 1 binary matrix
    img_bin_global = clear_border(img_as_uint(binary_global))

    # 0 1 binary matrix 
    img_bin_adaptive = clear_border(img_as_uint(binary_adaptive))


    bin_pos_mat = ocr.binary_matrix_to_position(binary_adaptive)

    np.savetxt("test.txt",bin_pos_mat) # %.5f specifies 5 decimal round
开发者ID:avanisho,项目名称:OCR,代码行数:22,代码来源:PythonStarter.py


示例20: test_adapthist_color

def test_adapthist_color():
    '''Test an RGB color uint16 image
    '''
    img = skimage.img_as_uint(data.lena())
    adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
    assert_almost_equal = np.testing.assert_almost_equal
    assert adapted.min() == 0
    assert adapted.max() == 1.0
    assert img.shape == adapted.shape
    full_scale = skimage.exposure.rescale_intensity(img)
    assert peak_snr(img, adapted) > 95.0
    assert norm_brightness_err(img, adapted) < 0.05
    return data, adapted
开发者ID:andersbll,项目名称:scikit-image,代码行数:13,代码来源:test_exposure.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python _build.cython函数代码示例发布时间:2022-05-27
下一篇:
Python skimage.img_as_ubyte函数代码示例发布时间: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