scikit-image

Convert boolean numpy array to pillow image

半世苍凉 提交于 2019-12-05 10:05:53
I'm currently working with image processing in python using the scikit-image library. I'm trying to make a binary image using sauvola thresholding with the following code: from PIL import Image import numpy from skimage.color import rgb2gray from skimage.filters import threshold_sauvola im = Image.open("test.jpg") pix = numpy.array(im) img = rgb2gray(pix) window_size = 25 thresh_sauvola = threshold_sauvola(img, window_size=window_size) binary_sauvola = img > thresh_sauvola Which gives the following result: the output is a numpy array with data type of this image is a bool [[ True True True ...

Uniform LBP with scikit-image local_binary_pattern function

久未见 提交于 2019-12-05 08:22:40
I'm using the local_binary_pattern from skimage.feature with uniform mode like this: >>> from skimage.feature import local_binary_pattern >>> lbp_image=local_binary_pattern(some_grayscale_image,8,2,method='uniform') >>> histogram=scipy.stats.itemfreq(lbp_image) >>> print histogram [[ 0.00000000e+00 1.57210000e+04] [ 1.00000000e+00 1.86520000e+04] [ 2.00000000e+00 2.38530000e+04] [ 3.00000000e+00 3.23200000e+04] [ 4.00000000e+00 3.93960000e+04] [ 5.00000000e+00 3.13570000e+04] [ 6.00000000e+00 2.19800000e+04] [ 7.00000000e+00 2.46530000e+04] [ 8.00000000e+00 2.76230000e+04] [ 9.00000000e+00 4

Numpy View Reshape Without Copy (2d Moving/Sliding Window, Strides, Masked Memory Structures)

那年仲夏 提交于 2019-12-05 07:09:24
I have an image stored as a 2d numpy array (possibly multi-d). I can make a view onto that array that reflects a 2d sliding window, but when I reshape it so that each row is a flattened window (rows are windows, column is a pixel in that window) python makes a full copy. It does this because I'm using the typical stride trick, and the new shape isn't contiguous in memory. I need this because I'm passing entire large images to an sklearn classifier, which accepts 2d matrices, where there's no batch/partial fit procedure, and the full expanded copy is far too large for memory. My Question: Is

Draw a gradual change ellipse in skimage

筅森魡賤 提交于 2019-12-05 06:02:31
问题 I want to draw an ellipse mask in skimage with gradual change color. The color changes starting from inside ellipse and end at outside ellipse. How to draw it with skimage or open-cv? Like image below: 回答1: Introduction Let's start by describing the sample image in detail. It is a 4 channel image (RGB + alpha transparency), but it only uses shades of gray. The image fits the drawing quite well, there's only a minimal margin around the shape. There is a filled, anti-aliased, rotated outer

ImportError cannot import name BytesIO when import caffe on ubuntu

前提是你 提交于 2019-12-04 23:04:44
问题 I am trying to make caffe running on my machine equipped with Ubuntu 12.04LTS. After finishing all the steps on the Installation page, I trained the LeNet model successfully and tried to use it as the tutorial from here. Then I got the following error: Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named caffe Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in

Geometric warp of image in python

风格不统一 提交于 2019-12-04 18:34:35
问题 I would like to use python to perform a geometric transform over an image, to 'straighten' or rectify an image along a given curve. It seems that scikit-image ProjectiveTransform() and warp() are very good for this, but the documentation is sparse. I followed the documentation here, but I couldn't get it to work properly for a sample case. Here's an example: I'll create an image with two concentric circles, and the goal is to rectify one quarter of these circles, so that the resulting image

Extract blocks or patches from NumPy Array

大兔子大兔子 提交于 2019-12-04 17:07:14
问题 I have a 2-d numpy array as follows: a = np.array([[1,5,9,13], [2,6,10,14], [3,7,11,15], [4,8,12,16]] I want to extract it into patches of 2 by 2 sizes with out repeating the elements. The answer should exactly be the same. This can be 3-d array or list with the same order of elements as below: [[[1,5], [2,6]], [[3,7], [4,8]], [[9,13], [10,14]], [[11,15], [12,16]]] How can do it easily? In my real problem the size of a is (36, 72). I can not do it one by one. I want programmatic way of doing

Robustly estimate Polynomial geometric transformation with scikit-image and RANSAC

心不动则不痛 提交于 2019-12-04 17:02:53
I would like to robustly estimate a polynomial geometric transform with scikit-image skimage.transform and skimage.measure.ransac The ransack documentation gives a very nice example of how to do exactly that but with a Similarity Transform. Here is how it goes: from skimage.transform import SimilarityTransform from skimage.measure import ransac model, inliers = ransac((src, dst), SimilarityTransform, 2, 10) I need to use skimage.transform.PolynomialTransform instead of SimilarityTransform, and I need to be able to specify the polynomial order. But the RANSAC call takes as input the

How can I get a full medial-axis line with its perpendicular lines crossing it?

时光毁灭记忆、已成空白 提交于 2019-12-04 17:01:07
I have an image and I want to get the pixels that cross through its medial axis. I tried to use skeletonize and medial axis methods in order to get them but both methods return one dimensional line which is shorter than the corresponding object. Here's the code with a sample image:- >>> import skimage.filter >>> import skimage.morphology >>> import numpy as np >>> import scipy.misc >>> im=scipy.misc.imread('img.jpg') >>> thr=skimage.filter.threshold_otsu(im) >>> im=im > thr # Threshold the image >>> im_sk=skimage.morphology.skeletonize(im) >>> mask=np.where(im_sk==1) # pixels of skeleton >>>

Gap Filling Contours / Lines

淺唱寂寞╮ 提交于 2019-12-04 14:28:12
问题 I have the following image: and I would like to fill in its contours (i.e. I would like to gap fill the lines in this image). I have tried a morphological closing, but using a rectangular kernel of size 3x3 with 10 iterations does not fill in the entire border. I have also tried a 21x21 kernel with 1 iteration and also not had luck. UPDATE: I have tried this in OpenCV (Python) using: cv2.morphologyEx(img, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_RECT, (21,21))) and cv2