scikit-image

Removing labels in scikit-image

微笑、不失礼 提交于 2019-12-11 14:57:43
问题 I have labeled an binary image imageLabels = morphology.label(imageBinary, background=255) However when I check the number of labels, I get 535 elements. print(len(imageLabels)) As a solution for this I thought about using measure.regionprops in order to remove the labels with a small pixel area. How would you guys approach this? I have tried the following, but for one reason or another the new array is no longer seen as a correct label element. i=0 for labelprop in measure.regionprops

scikit-image Gabor filter error: `filter weights array has incorrect shape`

我只是一个虾纸丫 提交于 2019-12-11 13:47:55
问题 Input is a greyscale image, converted to a 130x130 numpy matrix. I always get the error: Traceback (most recent call last): File "test_final.py", line 87, in <module> a._populate_gabor() File "C:\Users\Bears\Dropbox\School\Data Science\final.py", line 172, in _populate_gabor self.gabor_imgs[i] = self._matrix_2_1d(self._gabor_this(self.grey_imgs[i]),kernels[0]) File "C:\Users\Bears\Dropbox\School\Data Science\final.py", line 179, in _gabor_this filtered = ndi.convolve(image, kernel, mode=

NumPy Array Indexing and Replacing

一笑奈何 提交于 2019-12-11 11:32:45
问题 I have a 3d numpy array as follows: (3L, 5L, 5L) If one element in 3d positions, for instance, [150, 160, 170] exists. How can I convert all of them into [0,0,0] ? import numpy as np a = np.ones((3,5,5)) a[0,2:4,2:4] = 150 a[0,0:1,0:1] = 150 #important! a[1,2:4,2:4] = 160 a[2,2:4,2:4] = 170 print a The expected result should be: [[[ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.] [ 1. 1. 0. 0. 1.] [ 1. 1. 0. 0. 1.] [ 1. 1. 1. 1. 1.]] [[ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.] [ 1. 1. 0. 0. 1.] [ 1. 1. 0. 0. 1.]

Convection of an image using optical flow

旧街凉风 提交于 2019-12-11 09:13:44
问题 I have two images (frame1 and frame2) and I am able to calculate u,v using opencv: flow = cv2.calcOpticalFlowFarneback(prvs,next, 0.5, 1, 3, 15, 3, 5, 1, 0) I want to translate frame1 using this u,v to quantify the quality of the difference using various optical flow methods. I intend to extrapolate using these u,v. Is there a simple way to achieve this? 回答1: One way to compute a simple translation is to average the flow: avg_u = np.mean(flow[:, :, 0]) avg_v = np.mean(flow[:, :, 1]) This

Shear an image without cropping

孤街浪徒 提交于 2019-12-11 06:05:44
问题 I am trying to do a shear transformation on images using python. I am using skimage (scikit-image), opencv or similar can also do the job i think. The problem is whenever I try to shear using affine transform and warp (skimage) the image appears "cropped" or "clipped" (some parts of the "sheared" image are lost) which has sense as far as shear transform moves pixels (involves a translation of pixels). I need that the "canvas" supporting the image scale so the "sheared" image fit in a new

Using skimage for non-rectangular image areas

纵然是瞬间 提交于 2019-12-11 05:47:26
问题 Let's say I'm concerned with part of an image that I'm wanting to calculate a GLCM for that's not rectangular. How should I go about this? I've made a masking procedure that zeroes out the portion of the image that I don't care about, I just don't know how to take this "masked" image without considering the zeroed out portions of the image... Thanks for your help! 回答1: If you are able to assign the zero intensity value to background pixels, you can obtain the GLCM of the region of interest by

Why skimage mean filter does not work on float array?

送分小仙女□ 提交于 2019-12-11 04:24:57
问题 I am going to apply a mean filter on an array of float with window_size=3 for example. I have found this library: from skimage.filters.rank import mean import numpy as np x=np.array([[1,8,10], [5,2,9], [7,2,9], [4,7,10], [6,14,10]]) print(x) print(mean(x, square(3))) [[ 1 8 10] [ 5 2 9] [ 7 2 9] [ 4 7 10] [ 6 14 10]] [[ 4 5 7] [ 4 5 6] [ 4 6 6] [ 6 7 8] [ 7 8 10]] but this function can't run on float arrays: from skimage.filters.rank import mean import numpy as np x=np.array([[1,8,10], [5,2,9

Image processing - eliminate arc-like smears

僤鯓⒐⒋嵵緔 提交于 2019-12-11 04:24:47
问题 I am dealing with this kind of image (upper is post-processed) (lower is raw) So, first I converted the grayscale image into pure black and white binary image. I am interested in detecting the white blobs, and want to get rid of the arc-like smears in the corners. How can I do that? I general, I know that my targets are almost circular in shape, not too big, but I want to encode something that automatically gets rid of everything else, like the lighter arcs in the upper left and right corners

fastest way to iterate over all pixels of an image in python

妖精的绣舞 提交于 2019-12-10 15:48:34
问题 i have already read an image as an array : import numpy as np from scipy import misc face1=misc.imread('face1.jpg') face1 dimensions are (288, 352, 3) i need to iterate over every single pixel and populate a y column in a training set i took the following approach : Y_training = np.zeros([1,1],dtype=np.uint8) for i in range(0, face1.shape[0]): # We go over rows number for j in range(0, face1.shape[1]): # we go over columns number if np.array_equiv(face1[i,j],[255,255,255]): Y_training=np

scikit-image: write a ndarray to image with imsave, read back with imread, data don't match

霸气de小男生 提交于 2019-12-10 15:18:35
问题 here is the minimum working example: import numpy as np from skimage.io import imsave, imread image = np.array([[[109, 232, 173], [ 55, 35, 144]], [[ 43, 124, 185], [234, 127, 246]]], dtype=np.uint8) imsave("test.jpg", image) rb_image = imread("test.jpg") print("original image") print(image) print("read back image") print(rb_image) after run it, the result is, the ndarray read back from file don't match with original image [[[109 232 173] [ 55 35 144]] [[ 43 124 185] [234 127 246]]] read back