LIKE CODING: MJ [49] Upsampling
you have an img data as an array, output the data for upsampling. For example,
[1, 2, 3, 4, 5, 6] as width 3(2 rows) ==> upsample 2 times would be [1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6]
http://www.mitbbs.com/article_t/JobHunting/33110511.html
int cols = width * times;
int rows = input.size()/width + (input.size() % width == 0 ) ? 0 : 1;
vector<vector<int>> ret(rows, vector<int>(cols, 0));
for (int i=0; i < rows; ++i) {
for (int j=0; j < cols; ++j) {
ret[i][j] = input[i*width+j/times];
}
}
// do some boundary handling here
少两个loop,清晰点:)
一个for loop就可以啦
def upsampling(arr, width, times):
new_width = width*times
new_height = len(arr)/width*times
ans = [None]*new_width*new_height
for i in xrange(len(ans)):
row, col = i/new_width/times, i%new_width/times
ori_index = row*width + col
ans[i] = arr[ori_index]
return ans
Read full article from LIKE CODING: MJ [49] Upsampling
you have an img data as an array, output the data for upsampling. For example,
[1, 2, 3, 4, 5, 6] as width 3(2 rows) ==> upsample 2 times would be [1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6]
vector<int> unsampling(vector<int> &vec, int width, int times){ int rows = (int)vec.size()/width; int m = rows*times, n = width*times; int index = 0; vector<int> ret(m*n); while(index<m*n){ int i = index/n, j = index%n; ret[index++] = vec[i/times*width+(j/times)%width]; } PrintVector(ret, "ret"); return ret;}int main(){ vector<int> vec = {1,2,3,4,5,6}; unsampling(vec, 3, 2); return 0;}int cols = width * times;
int rows = input.size()/width + (input.size() % width == 0 ) ? 0 : 1;
vector<vector<int>> ret(rows, vector<int>(cols, 0));
for (int i=0; i < rows; ++i) {
for (int j=0; j < cols; ++j) {
ret[i][j] = input[i*width+j/times];
}
}
// do some boundary handling here
少两个loop,清晰点:)
一个for loop就可以啦
def upsampling(arr, width, times):
new_width = width*times
new_height = len(arr)/width*times
ans = [None]*new_width*new_height
for i in xrange(len(ans)):
row, col = i/new_width/times, i%new_width/times
ori_index = row*width + col
ans[i] = arr[ori_index]
return ans
Read full article from LIKE CODING: MJ [49] Upsampling