c++ - Variable Domain Reduction in Halide -


right i'm trying write halide code subsamples image. want every 2 2 square of image reduced 1 pixel contains maximum. simple example transforming

1 2 3 4 5 6 7 8 9 0 1 2 4 3 5 6 

into

6 8 9 6 

right i'm trying along lines of (i'm aware give sum instead of maximum, it's toy example of same process):

halide::image<uint8_t> input = load<uint8_t>("test.png");         halide::image<uint8_t> output(input.width() / 2, input.height() / 2, input.channels());   halide::func subsample;  halide::var c;   (int = 0; < input.height(); += 2) {      (int j = 0; j < input.width(); j += 2) {          halide::rdom r = halide::rdom(i, 2, j, 2);          subsample(i, j, c) += input(r.x, r.y, c);      }  }   subsample.realize(output);  save(output, "test.png"); 

however, code runs infinitely. (i'm not sure why). know can use halide::rdom represent reduce operation on range. however, in no example find can pass variable random domain object.

edit:

after playing around halide more, able construct this:

subsample(x, y, c) = halide::max(input(2*x,2*y,c),input(2*x+1,2*y,c)); subsample(x, y, c) = halide::max(subsample(x,y,c),input(2*x,2*y+1,c)); subsample(x, y, c) = halide::max(subsample(x,y,c),input(2*x+1,2*y+1,c)); 

to 2x2 max reduction. however, when put in loop, won't call because cannot defined. there anyway put in terms of domain reduction?

i think argmax (which embedded halide function) can used want :)

#include "halide.h" #include <stdio.h>  uint8_t data[16] = {     1, 2, 3, 4,     5, 6, 7, 8,     9, 0, 1, 2,     3, 4, 5, 6 };  using namespace halide;  int main(int argc, char** argv) {     halide::image<uint8_t> input(4, 4);      for(int j = 0; j < 4; j++) {         for(int = 0; < 4; i++) {             input(j, i) = data[j*4 + i];         }     }      halide::func f, max2x2;     halide::var x, y, dx, dy;     halide::expr x_ = x * 2;     halide::expr y_ = y * 2;      f(x, y, dx, dy) = input(x_ + dx, y_ + dy);      rdom r(0, 2, 0, 2);     max2x2(x, y) = argmax(f(x, y, r.x, r.y))[2];      halide::image<uint8_t> output(2, 2);     max2x2.realize(output);      for(int j = 0; j < 2; j++) {         for(int = 0; < 2; i++) {             printf("%d ", output(j, i));         }         printf("\n");     }     return 0; } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -