vectorization

C# - How to convert byte array of image pixels data to grayscale using vector SSE operation

心不动则不痛 提交于 2020-01-24 22:12:02
问题 I have a problem with converting the image data stored in byte[] array to grayscale. I want to use vector SIMD operations because in future a need to write ASM and C++ DLL files to measure operations time. When I read about SIMD I found that SSE command is operation on 128-bit registers so there is a problem because I need to convert my byte[] array into few Vector<T> stored into List<T>. Image is four channels RGBA JPEG so I need also to know how to create vectors with R, G, B data based on

C# - How to convert byte array of image pixels data to grayscale using vector SSE operation

删除回忆录丶 提交于 2020-01-24 22:12:00
问题 I have a problem with converting the image data stored in byte[] array to grayscale. I want to use vector SIMD operations because in future a need to write ASM and C++ DLL files to measure operations time. When I read about SIMD I found that SSE command is operation on 128-bit registers so there is a problem because I need to convert my byte[] array into few Vector<T> stored into List<T>. Image is four channels RGBA JPEG so I need also to know how to create vectors with R, G, B data based on

Python3: vectorizing nested loops

会有一股神秘感。 提交于 2020-01-24 20:43:06
问题 I have this function: def fun(x): # x is a vector with size: (size_x*size_y) = n c = 0 f_vec = np.zeros((size_x*size_y)) for i in range(size_x): for j in range(size_y): f_vec[c]=i*j*x[c] c=c+1 return f_vec I do this because what happens is that the vector x is (considering size_x=4 and size_y=3) x[0]=x00 #c=0 i=0,j=0 x[1]=x01 #c=1 i=0, j=1 x[2]=x02 #c=2 i=0. j=size_y-1 x[3]=x10 #c=3 i=1, j=0 x[4]=x11 ... x[n]=x32 #c=n i=size_x-1, j= size_y-1 Can I avoid the nested loop and do a simple vector

TensorFlow: bincount with axis option

蹲街弑〆低调 提交于 2020-01-24 14:05:49
问题 In TensorFlow, I can get the count of each element in an array with tf.bincount: x = tf.placeholder(tf.int32, [None]) freq = tf.bincount(x) tf.Session().run(freq, feed_dict = {x:[2,3,1,3,7]}) this returns Out[45]: array([0, 1, 1, 2, 0, 0, 0, 1], dtype=int32) Is there a way to do this on a 2D tensor? i.e. x = tf.placeholder(tf.int32, [None, None]) freq = tf.axis_bincount(x, axis = 1) tf.Session().run(freq, feed_dict = {x:[[2,3,1,3,7],[1,1,2,2,3]]}) that returns [[0, 1, 1, 2, 0, 0, 0, 1],[0, 2,

Is there any OSS library or paper that does Vector path tracing of mono bitmaps?

落花浮王杯 提交于 2020-01-24 00:37:27
问题 i am just interested in how these things work and am after a library or paper that describes the approach that most of these take. At a guess they probably support a few basic constructs. line arc dot 回答1: A large part of image processing is about reasoning about an image at a higher level of abstraction than just pixels, which is exactly what you need to do to vectorise an image. As such, OpenCV is well worth looking at. It contains various image processing functions for blob detection and

How to vectorize a simple for loop in Python/Numpy

邮差的信 提交于 2020-01-22 14:59:25
问题 I found dozens of examples how to vectorize for loops in Python/NumPy. Unfortunately, I don't get how I can reduce the computation time of my simple for loop using a vectorized form. Is it even possible in this case? time = np.zeros(185000) lat1 = np.array(([48.78,47.45],[38.56,39.53],...)) # ~ 200000 rows lat2 = np.array(([7.78,5.45],[7.56,5.53],...)) # same number of rows as time for ii in np.arange(len(time)): pos = np.argwhere( (lat1[:,0]==lat2[ii,0]) and \ (lat1[:,1]==lat2[ii,1]) ) if

MATLAB repeat numbers based on a vector of lengths

[亡魂溺海] 提交于 2020-01-22 11:14:25
问题 Is there a vectorised way to do the following? (shown by an example): input_lengths = [ 1 1 1 4 3 2 1 ] result = [ 1 2 3 4 4 4 4 5 5 5 6 6 7 ] I have spaced out the input_lengths so it is easy to understand how the result is obtained The resultant vector is of length: sum(lengths) . I currently calculate result using the following loop: result = ones(1, sum(input_lengths )); counter = 1; for i = 1:length(input_lengths) start_index = counter; end_index = counter + input_lengths (i) - 1; result

comparison of loop and vectorization in matlab

℡╲_俬逩灬. 提交于 2020-01-22 00:20:41
问题 let us consider following code for impulse function function y=impulse_function(n); y=0; if n==0 y=1; end end this code >> n=-2:2; >> i=1:length(n); >> f(i)=impulse_function(n(i)); >> returns result f f = 0 0 0 0 0 while this code >> n=-2:2; >> for i=1:length(n); f(i)=impulse_function(n(i)); end >> f f = 0 0 1 0 0 in both case i is 1 2 3 4 5,what is different? 回答1: Your function is not defined to handle vector input. Modify your impluse function as follows: function y=impulse_function(n) [a b

Multiplying 2d array by 1d array

大憨熊 提交于 2020-01-21 15:27:46
问题 I have an 2D-array a with shape (k,n) and I want to 'multiply' it with an 1D-array b of shape (m,): a = np.array([[2, 8], [4, 7], [1, 2], [5, 2], [7, 4]]) b = np.array([3, 5, 5]) As a result of the 'multiplication' I'm looking for: array([[[2*3,2*5,2*5],[8*3,8*5,8*5]], [[4*3,4*5,4*5],[7*3,7*5,7*5]], [[1*3,1*5,1*5], ..... ]], ................. ]]]) = array([[[ 6, 10, 10], [24, 40, 40]], [[12, 20, 20], [21, 35, 35]], [[ 3, 5, 5], [ ........ ]], ....... ]]]) I could solve it with a loop of

Vectorize() vs apply()

限于喜欢 提交于 2020-01-20 03:16:07
问题 The Vectorize() and the apply() functions in R can often be used to accomplish the same goal. I usually prefer vectorizing a function for readability reasons, because the main calling function is related to the task at hand while sapply is not. It is also useful to Vectorize() when I am going to be using that vectorized function multiple times in my R code. For instance: a <- 100 b <- 200 c <- 300 varnames <- c('a', 'b', 'c') getv <- Vectorize(get) getv(varnames) vs sapply(varnames, get)