X-Git-Url: http://www.fmaj7b5.info/git?p=cuda.git;a=blobdiff_plain;f=binarize%2Fbinarize.cpp;fp=binarize%2Fbinarize.cpp;h=940132e54fe1dc5991bcc99944b2479ab59da9c6;hp=0000000000000000000000000000000000000000;hb=7b77a912a4a1202f677ae9dbff672758e2b945e4;hpb=8b2c111ed060599c6bc93b48732d36f8aa48eb2b diff --git a/binarize/binarize.cpp b/binarize/binarize.cpp new file mode 100644 index 0000000..940132e --- /dev/null +++ b/binarize/binarize.cpp @@ -0,0 +1,69 @@ +/* + Copyright (C) 2012 fmaj7b5.info + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +// binarize.cpp : ƒRƒ“ƒ\[ƒ‹ ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚̃Gƒ“ƒgƒŠ ƒ|ƒCƒ“ƒg‚ð’è‹`‚µ‚Ü‚·B +// + +#include "stdafx.h" + +#include "Image.h" +#include "ImageIO.h" + +#include "binarize.h" + +using namespace FM7b5; + +static void binarize_cpu(ImageGray& out, const ImageGray& in, const uint8_t thres = 128); + +int _tmain(int argc, _TCHAR* argv[]) +{ + const uint8_t thres(128); + ImageGray image; + + try { + image = loadPGM("..\\img\\sine.pgm"); + } + catch (std::exception& e) + { + std::cout << e.what() << std::endl; + return -1; + } + + ImageGray out(image.width(), image.height()); + binarize_cpu(out, image, thres); + savePNM(out, "result_cpu.pgm"); + + ImageGray out_gpu(image.width(), image.height()); + binarize_gpu(out_gpu, image, thres); + savePNM(out_gpu, "result_gpu.pgm"); + + return 0; +} + +void +binarize_cpu(ImageGray& out, const ImageGray& in, const uint8_t thres) +{ + if (in.width() != out.width() || in.height() != out.height()) { + throw std::runtime_error("sizes of input and output images are diferent."); + } + + for (size_t h = 0; h < in.height(); ++h) { + for (size_t w = 0; w < in.width(); ++w) { + out(w, h) = (in(w, h) < thres) ? 0 : 255; + } + } +}