Created
September 3, 2014 00:33
-
-
Save jrk/41c4f94f03a439b145b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ local_histogram*.cpp -g -I ../include -L ../bin -lHalide -o local_histogram | |
// DYLD_LIBRARY_PATH=../bin ./local_histogram | |
#include <Halide.h> | |
#include <stdio.h> | |
using namespace Halide; | |
#include "image_io.h" | |
int main(int argc, char **argv) { | |
Var x,y,v; | |
Image<uint8_t> img = load<uint8_t>("images/gray.png"); | |
// Create a level image | |
Func level_image("level_image"); | |
level_image(x,y,v) = cast<uint8_t>(0); | |
level_image(x,y,img(x,y)) = cast<uint8_t>(1); | |
level_image.compute_root().parallel(y); | |
// Clamp level image | |
Func clamped_lir("clamped_lir"); | |
Expr clamped_x = clamp(x, 0, img.width()-1); | |
Expr clamped_y = clamp(y, 0, img.height()-1); | |
clamped_lir(x,y,v) = clamp(level_image(clamped_x, clamped_y, v), 0, 63); | |
// Naive histogram (vertical only) | |
Func hist1("hist1"); | |
RDom r(-2,5); | |
hist1(x,y,v) = sum(clamped_lir(x,y+r,v)); | |
// fprintf(stderr, "Start..."); | |
// auto out = hist1.realize(img.width(), img.height(), 64); | |
// fprintf(stderr, "done.\n"); | |
// "Smart" histogram (vertical only) | |
Func hist2("hist2"); | |
hist2(x,y,v) = cast<uint8_t>(0); | |
// RDom r(-2,5); | |
hist2(x,0,v) = sum(clamped_lir(x,r,v)); | |
RDom ry(1, img.height()-1); | |
hist2(x,ry,v) = hist2(x,ry-1,v) - clamped_lir(x,ry-3,v) + clamped_lir(x,ry+2,v); | |
fprintf(stderr, "Start..."); | |
auto out = hist2.realize(img.width(), img.height(), 64); | |
fprintf(stderr, "done.\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment