median

Two dimensional array median filtering

陌路散爱 提交于 2019-12-11 09:33:27
问题 I'm trying to write code that implements median filtering on a two-dimensional array. Here's an image to illustrate: The program starts at the beginning of the array. The maximum array size is 100. I know that I can use an array like: int a[100][100]; to store the input, and that I can iterate over a part of this array using two for loops like this: for(i=0;i<size_filter;i++) for(j=0;j<size_filter;j++) temp[i][j]=a[i][j] // not so sure But how can I make this code loop over the neighbors of

Computing moving median with scipy generic_filter and numpy median_filter gives different outputs

筅森魡賤 提交于 2019-12-11 06:47:35
问题 I am looking to implement a fast moving median as I have to do a lot of medians for my program. I would like to use python builtins functions as they would be more optimized than what I could do. My median should do : - extract 5 values, - remove the center one, - find the median of the remaining 4 values. Basically multiple calls to : numpy.median(np.array([0, 1, 2, 3, 4])[np.array([True, True, False, True, True])]) # (1. + 3.) / 2. = 2.0 I have found two functions : scipy generic_filter and

Rolling (moving) median in Greenplum

早过忘川 提交于 2019-12-11 04:59:51
问题 I would like to calculate the rolling median for a column in Greenplum, i.e. as below: | x | rolling_median_x | | -- + ---------------- | | 4 | 4 | | 1 | 2.5 | | 3 | 3 | | 2 | 2.5 | | 1 | 2 | | 6 | 2.5 | | 9 | 3 | x is an integer and for each row rolling_median_x shows the median of x for the current and preceding rows. E.g. for the third row rolling_median_x = median(4, 1, 3) = 3 . Things I've found out so far: the median function can't be used as a framed window function, i.e. median(x)

2D median filtering in CUDA: how to efficiently copy global memory to shared memory

落爺英雄遲暮 提交于 2019-12-11 01:42:27
问题 I'm trying to do a median filter with a window x*y where x and y are odd and parameters of the program. My idea is first see how many threads I can execute in a single block and how much shared memory I have avaliable, like this: void cudaInit(int imgX, int imgY, int kx, int ky, int* cudaVars){ int device; int deviceCount; cudaDeviceProp deviceProp; cudaGetDevice(&device); cudaGetDeviceProperties(&deviceProp, device); int kxMed = kx/2; int kyMed = ky/2; int n = deviceProp.maxThreadsPerBlock;

Calculate Median Image in Matlab

走远了吗. 提交于 2019-12-10 18:14:22
问题 I am new to matlab, so forgive me if i am asking for the obvious here: what i have is a collection of color photographic images (all the same dimensions). What i want to do is calculate the median color value for each pixel. I know there is a median filter in matlab, but as far as i know it does not do exactly what i want. Because i want to calculate the median value between the entire collection of images, for each separate pixel. So for example, if i have three images, i want matlab to

Median of a list with NaN values removed, in python

独自空忆成欢 提交于 2019-12-10 17:26:02
问题 Is it possible to calculate the median of a list without explicitly removing the NaN's, but rather, ignoring them? I want median([1,2,3,NaN,NaN,NaN,NaN,NaN,NaN]) to be 2, not NaN. 回答1: numpy 1.9.0 has the function nanmedian : nanmedian(a, axis=None, out=None, overwrite_input=False, keepdims=False) Compute the median along the specified axis, while ignoring NaNs. Returns the median of the array elements. .. versionadded:: 1.9.0 E.g. >>> from numpy import nanmedian, NaN >>> nanmedian([1,2,3,NaN

SQL ranking query to compute ranks and median in sub groups

廉价感情. 提交于 2019-12-10 03:34:21
问题 I want to compute the Median of y in sub groups of this simple xy_table : x | y --groups--> gid | x | y --medians--> gid | x | y ------- ------------- ------------- 0.1 | 4 0.0 | 0.1 | 4 0.0 | 0.1 | 4 0.2 | 3 0.0 | 0.2 | 3 | | 0.7 | 5 1.0 | 0.7 | 5 1.0 | 0.7 | 5 1.5 | 1 2.0 | 1.5 | 1 | | 1.9 | 6 2.0 | 1.9 | 6 | | 2.1 | 5 2.0 | 2.1 | 5 2.0 | 2.1 | 5 2.7 | 1 3.0 | 2.7 | 1 3.0 | 2.7 | 1 In this example every x is unique and the table is already sorted by x . I now want to GROUP BY round(x) and

Using MEDIAN along side MAX, MIN, and AVG functions in MySQL

社会主义新天地 提交于 2019-12-09 12:24:30
问题 I have the following MySQL query which is working perfectly: select count(*) as `# of Data points`, name, max((QNTY_Sell/QNTYDelivered)*1000) as `MAX Thousand Price`, min((QNTY_Sell/QNTYDelivered)*1000) as `MIN Thousand Price`, avg((QNTY_Sell/QNTYDelivered)*1000) as `MEAN Thousand Price` from table_name where year(date) >= 2012 and name like "%the_name%" and QNTYDelivered > 0 and QNTY_Sell > 0 group by name order by name; Now I wish to also add a result column that gives me the MEDIAN of the

How to find k nearest neighbors to the median of n distinct numbers in O(n) time?

社会主义新天地 提交于 2019-12-09 04:18:29
问题 I can use the median of medians selection algorithm to find the median in O(n). Also, I know that after the algorithm is done, all the elements to the left of the median are less that the median and all the elements to the right are greater than the median. But how do I find the k nearest neighbors to the median in O(n) time? If the median is n, the numbers to the left are less than n and the numbers to the right are greater than n. However, the array is not sorted in the left or the right

Generic Method to find the median of 3 values

痴心易碎 提交于 2019-12-08 17:05:27
问题 I needed a method to get the median of 3 values, I thought it a good opportunity to write a generic method since I don't really have that practiced. I wrote this and it seems pretty straight-forward, though I get a warning, but it seems to work fine, according to my tests. I'm aware I could use an inherently sorted set, or Collections.sort() , but this approach is for the sake of understanding. I want to pinpoint a few things: I noticed this doesn't work if I tried to declare medianHelper