|
Toshihiro Shimizu |
890ddd |
#include <string></string>
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdexcept></stdexcept>
|
|
Toshihiro Shimizu |
890ddd |
#include <fstream></fstream>
|
|
Toshihiro Shimizu |
890ddd |
#include <limits></limits>
|
|
Toshihiro Shimizu |
890ddd |
#include <cmath></cmath>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_ifx_common.h" /* igs::image::rgba */
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_gaussian_blur.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_gauss_distribution.cpp"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int diameter_from_radius_(const int radius)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/* テーブルの半径サイズ(=中心位置)からテーブルの大きさを決める */
|
|
Toshihiro Shimizu |
890ddd |
return radius * 2 + 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class rt=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void blur_1st_hori_(
|
|
Toshihiro Shimizu |
890ddd |
const double **in_plane_with_margin // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int height_with_margin, const int width_with_margin, double *brush_sequence // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int int_radius, double **out_plane_with_margin // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 参照画像用情報(no margin) */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref /* 求める画像(out)と同じ高さ、幅、チャンネル数 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_mode /* 0=R,1=G,2=B,3=A,4=Luminance,5=Nothing */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_channels, const double real_radius, const double sigma)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int brush_diameter = diameter_from_radius_(int_radius);
|
|
Toshihiro Shimizu |
890ddd |
const int width_no_margin = width_with_margin - int_radius * 2;
|
|
Toshihiro Shimizu |
890ddd |
const int r_max = std::numeric_limits<rt>::max();</rt>
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref_vert = ref;
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref_hori = ref;
|
|
Toshihiro Shimizu |
890ddd |
double before_real_radius = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 縦方向 */
|
|
Toshihiro Shimizu |
890ddd |
for (int yo = 0; yo < height_with_margin; ++yo) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ref != 0) {
|
|
Toshihiro Shimizu |
890ddd |
if (int_radius < yo && yo < (height_with_margin - int_radius)) {
|
|
Toshihiro Shimizu |
890ddd |
ref_vert += width_no_margin * ref_channels;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ref_hori = ref_vert;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 横方向 */
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0, xo = int_radius; xx < width_no_margin; ++xx, ++xo) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ref != 0) {
|
|
Toshihiro Shimizu |
890ddd |
const double read_r = real_radius * igs::color::ref_value(
|
|
Toshihiro Shimizu |
890ddd |
ref_hori, ref_channels, r_max, ref_mode);
|
|
Toshihiro Shimizu |
890ddd |
ref_hori += ref_channels;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (read_r != before_real_radius) {
|
|
Toshihiro Shimizu |
890ddd |
gauss_distribution_1d_(
|
|
Toshihiro Shimizu |
890ddd |
brush_sequence, brush_diameter, igs::gaussian_blur_hv::int_radius(read_r), read_r, sigma);
|
|
Toshihiro Shimizu |
890ddd |
before_real_radius = read_r;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* ガウス分布で横blur */
|
|
Toshihiro Shimizu |
890ddd |
double accum = 0;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
for (int xb=0, xi=xx; xb
|
|
Toshihiro Shimizu |
890ddd |
accum += in_plane_with_margin[yo][xi] * brush_sequence[xb];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
const double *bru_seq = brush_sequence;
|
|
Toshihiro Shimizu |
890ddd |
int bru_dia = brush_diameter;
|
|
Toshihiro Shimizu |
890ddd |
const double *inn_pla = &in_plane_with_margin[yo][xx];
|
|
Toshihiro Shimizu |
890ddd |
while (0 < bru_dia--) {
|
|
Toshihiro Shimizu |
890ddd |
accum += (*inn_pla++) * (*bru_seq++);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
out_plane_with_margin[yo][xo] = accum;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class rt=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void blur_2nd_vert_(
|
|
Toshihiro Shimizu |
890ddd |
const double **in_plane_with_margin // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int height_with_margin, const int width_with_margin, double *brush_sequence // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int int_radius, double **out_plane_with_margin // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 参照画像用情報(no margin) */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref /* 求める画像(out)と同じ高さ、幅、チャンネル数 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_mode /* 0=R,1=G,2=B,3=A,4=Luminance,5=Nothing */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_channels, const double real_radius, const double sigma)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int brush_diameter = diameter_from_radius_(int_radius);
|
|
Toshihiro Shimizu |
890ddd |
const int height_no_margin = height_with_margin - int_radius * 2;
|
|
Toshihiro Shimizu |
890ddd |
const int width_no_margin = width_with_margin - int_radius * 2;
|
|
Toshihiro Shimizu |
890ddd |
const int r_max = std::numeric_limits<rt>::max();</rt>
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref_vert = ref;
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref_hori = ref;
|
|
Toshihiro Shimizu |
890ddd |
double before_real_radius = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 左右マージン部分はもう処理しなくていい */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 横方向 */
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0, xo = int_radius; xx < width_no_margin; ++xx, ++xo) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ref != 0) {
|
|
Toshihiro Shimizu |
890ddd |
ref_hori += ref_channels;
|
|
Toshihiro Shimizu |
890ddd |
ref_vert = ref_hori;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 縦方向 */
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0, yo = int_radius; yy < height_no_margin; ++yy, ++yo) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ref != 0) {
|
|
Toshihiro Shimizu |
890ddd |
const double read_r = real_radius * igs::color::ref_value(
|
|
Toshihiro Shimizu |
890ddd |
ref_vert, ref_channels, r_max, ref_mode);
|
|
Toshihiro Shimizu |
890ddd |
ref_vert += width_no_margin * ref_channels;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (read_r != before_real_radius) {
|
|
Toshihiro Shimizu |
890ddd |
gauss_distribution_1d_(
|
|
Toshihiro Shimizu |
890ddd |
brush_sequence, brush_diameter, igs::gaussian_blur_hv::int_radius(read_r), read_r, sigma);
|
|
Toshihiro Shimizu |
890ddd |
before_real_radius = read_r;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* ガウス分布で横blur */
|
|
Toshihiro Shimizu |
890ddd |
double accum = 0;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
for (int yb=0,yi=yy; yb
|
|
Toshihiro Shimizu |
890ddd |
accum += in_plane_with_margin[yi][xo] * brush_sequence[yb];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
const double *bru_seq = brush_sequence;
|
|
Toshihiro Shimizu |
890ddd |
int bru_dia = brush_diameter;
|
|
Toshihiro Shimizu |
890ddd |
const double *inn_pla = &in_plane_with_margin[yy][xo];
|
|
Toshihiro Shimizu |
890ddd |
while (0 < bru_dia--) {
|
|
Toshihiro Shimizu |
890ddd |
accum += (*inn_pla) * (*bru_seq++);
|
|
Toshihiro Shimizu |
890ddd |
inn_pla += width_with_margin;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
out_plane_with_margin[yo][xo] = accum;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void get_(
|
|
Toshihiro Shimizu |
890ddd |
const T *in, const int height, const int width, const int channels, const int current_ch, double **out // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
in += current_ch;
|
|
Toshihiro Shimizu |
890ddd |
const double maxi = static_cast<double>(</double>
|
|
Toshihiro Shimizu |
890ddd |
std::numeric_limits<t>::max());</t>
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < height; ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0; xx < width; ++xx) {
|
|
Toshihiro Shimizu |
890ddd |
out[yy][xx] = static_cast<double>(*in) / maxi;</double>
|
|
Toshihiro Shimizu |
890ddd |
in += channels;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void put_margin_(
|
|
Toshihiro Shimizu |
890ddd |
const double **in_with_margin // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int height_with_margin, const int width_with_margin, const int channels, const int current_ch, const int margin, T *out_no_margin)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
out_no_margin += current_ch;
|
|
Toshihiro Shimizu |
890ddd |
const double maxi = static_cast<double>(</double>
|
|
Toshihiro Shimizu |
890ddd |
std::numeric_limits<t>::max()) +</t>
|
|
Toshihiro Shimizu |
890ddd |
0.999999;
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = margin; yy < (height_with_margin - margin); ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = margin; xx < (width_with_margin - margin); ++xx) {
|
|
Toshihiro Shimizu |
890ddd |
*out_no_margin = static_cast<t>(in_with_margin[yy][xx] * maxi);</t>
|
|
Toshihiro Shimizu |
890ddd |
out_no_margin += channels;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
bool diff_between_channel_(
|
|
Toshihiro Shimizu |
890ddd |
const T *in, const int height, const int width, const int channels, const int ch1, const int ch2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//if (ch1 == ch2) { return false; }
|
|
Toshihiro Shimizu |
890ddd |
//if (channels <= ch1) { return false; }
|
|
Toshihiro Shimizu |
890ddd |
//if (channels <= ch2) { return false; }
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < height; ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0; xx < width; ++xx) {
|
|
Toshihiro Shimizu |
890ddd |
if (in[ch1] != in[ch2]) {
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
in += channels;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class class="" it,="" rt=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void convert_hv_(
|
|
Toshihiro Shimizu |
890ddd |
const IT *in_with_margin, IT *out_no_margin, const int height_with_margin, const int width_with_margin, const int channels
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
double *filter // (double *)(&filter_buf.at(0))
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int int_radius, double **buffer_inn // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
double **buffer_out // &(std::vector<double *="">).at(0)</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 参照画像用情報(no margin) */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const RT *ref /* 求める画像(out)と同じ高さ、幅、チャンネル数 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_mode /* 0=R,1=G,2=B,3=A,4=Luminance,5=Nothing */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double real_radius, const double sigma)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool diff_sw = true; /* 1番目の画像は処理する */
|
|
Toshihiro Shimizu |
890ddd |
for (int cc = 0; cc < channels; ++cc) {
|
|
Toshihiro Shimizu |
890ddd |
if (0 < cc) { /* 2番目のチャンネル以後 */
|
|
Toshihiro Shimizu |
890ddd |
/* 1つ前のチャンネルと違いを調べる */
|
|
Toshihiro Shimizu |
890ddd |
diff_sw = diff_between_channel_(
|
|
Toshihiro Shimizu |
890ddd |
in_with_margin, height_with_margin, width_with_margin, channels, cc - 1, cc);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* 一つ前と同じ画像なら処理せず使い回して高速化する */
|
|
Toshihiro Shimizu |
890ddd |
if (diff_sw) {
|
|
Toshihiro Shimizu |
890ddd |
get_(
|
|
Toshihiro Shimizu |
890ddd |
in_with_margin, height_with_margin, width_with_margin, channels, cc, buffer_inn);
|
|
Toshihiro Shimizu |
890ddd |
blur_1st_hori_(
|
|
Toshihiro Shimizu |
890ddd |
(const double **)(buffer_inn), height_with_margin, width_with_margin, filter, int_radius, buffer_out
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
ref, ref_mode, channels, real_radius, sigma);
|
|
Toshihiro Shimizu |
890ddd |
blur_2nd_vert_(
|
|
Toshihiro Shimizu |
890ddd |
(const double **)(buffer_out), height_with_margin, width_with_margin, filter, int_radius, buffer_inn
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
ref, ref_mode, channels, real_radius, sigma);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
put_margin_(
|
|
Toshihiro Shimizu |
890ddd |
(const double **)(buffer_inn), height_with_margin, width_with_margin, channels, cc, int_radius, out_no_margin);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const int igs::gaussian_blur_hv::int_radius(
|
|
Toshihiro Shimizu |
890ddd |
const double real_radius)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/* ぼかしの半径から、pixelサイズ半径(=中心位置=margin)を決める */
|
|
Toshihiro Shimizu |
890ddd |
return static_cast<int>(ceil(real_radius));</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const int igs::gaussian_blur_hv::buffer_bytes(
|
|
Toshihiro Shimizu |
890ddd |
const int height_with_margin, const int width_with_margin, const int int_radius)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const int int_diameter = diameter_from_radius_(int_radius);
|
|
Toshihiro Shimizu |
890ddd |
return int_diameter * int_diameter * sizeof(double) + height_with_margin * width_with_margin * sizeof(double) + height_with_margin * width_with_margin * sizeof(double);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void igs::gaussian_blur_hv::convert(
|
|
Toshihiro Shimizu |
890ddd |
/* 入出力画像 */
|
|
Toshihiro Shimizu |
890ddd |
const void *in_with_margin, void *out_no_margin
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int height_with_margin, const int width_with_margin, const int channels, const int bits
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* Pixel毎に効果の強弱 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const unsigned char *ref /* 求める画像(out)と同じ高、幅、ch数 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_bits /* refがゼロのときはここもゼロ */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int ref_mode /* 0=R,1=G,2=B,3=A,4=Luminance,5=Nothing */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 計算バッファ */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
void *buffer, int buffer_bytes // Must be igs::gaussian_blur_hv::buffer_bytes(-)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* Action Geometry */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int int_radius // =margin
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double real_radius, const double sigma //= 0.25
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/* 引数チェック */
|
|
Toshihiro Shimizu |
890ddd |
if (real_radius <= 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((igs::image::rgba::siz != channels) && (igs::image::rgb::siz != channels) && (1 != channels) /* grayscale */
|
|
Toshihiro Shimizu |
890ddd |
) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error("Bad channels,Not rgba/rgb/grayscale");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 変数の設定 */
|
|
Toshihiro Shimizu |
890ddd |
const int int_diameter = diameter_from_radius_(int_radius);
|
|
Toshihiro Shimizu |
890ddd |
double *double_buffer = static_cast<double *="">(buffer);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* メモリバッファの設定 */
|
|
Toshihiro Shimizu |
890ddd |
std::vector<double> filter_buf(int_diameter);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<double *=""> in_plane_with_margin_dp(</double>
|
|
Toshihiro Shimizu |
890ddd |
height_with_margin);
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < height_with_margin; ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
in_plane_with_margin_dp.at(yy) = double_buffer;
|
|
Toshihiro Shimizu |
890ddd |
double_buffer += width_with_margin;
|
|
Toshihiro Shimizu |
890ddd |
buffer_bytes -= width_with_margin * sizeof(double);
|
|
Toshihiro Shimizu |
890ddd |
if (buffer_bytes <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
std::string msg("buffer_inn is empty");
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(msg);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<double *=""> out_plane_with_margin_dp(</double>
|
|
Toshihiro Shimizu |
890ddd |
height_with_margin);
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < height_with_margin; ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
out_plane_with_margin_dp.at(yy) = double_buffer;
|
|
Toshihiro Shimizu |
890ddd |
double_buffer += width_with_margin;
|
|
Toshihiro Shimizu |
890ddd |
buffer_bytes -= width_with_margin * sizeof(double);
|
|
Toshihiro Shimizu |
890ddd |
if (buffer_bytes <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
std::string msg("buffer_out is empty");
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(msg);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* filter生成 */
|
|
Toshihiro Shimizu |
890ddd |
gauss_distribution_1d_(
|
|
Toshihiro Shimizu |
890ddd |
&filter_buf.at(0), int_diameter, int_radius, real_radius, sigma);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 処理 */
|
|
Toshihiro Shimizu |
890ddd |
if ((std::numeric_limits<unsigned char="">::digits == bits) && ((std::numeric_limits<unsigned char="">::digits == ref_bits) || (0 == ref_bits))) {</unsigned></unsigned>
|
|
Toshihiro Shimizu |
890ddd |
convert_hv_(
|
|
Toshihiro Shimizu |
890ddd |
static_cast<const *="" char="" unsigned="">(in_with_margin), static_cast<unsigned *="" char="">(out_no_margin), height_with_margin, width_with_margin, channels, &filter_buf.at(0), int_radius, &in_plane_with_margin_dp.at(0), &out_plane_with_margin_dp.at(0)</unsigned></const>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
ref, ref_mode, real_radius, sigma);
|
|
Toshihiro Shimizu |
890ddd |
} else if ((std::numeric_limits<unsigned short="">::digits == bits) && ((std::numeric_limits<unsigned char="">::digits == ref_bits) || (0 == ref_bits))) {</unsigned></unsigned>
|
|
Toshihiro Shimizu |
890ddd |
convert_hv_(
|
|
Toshihiro Shimizu |
890ddd |
static_cast<const *="" short="" unsigned="">(in_with_margin), static_cast<unsigned *="" short="">(out_no_margin), height_with_margin, width_with_margin, channels, &filter_buf.at(0), int_radius, &in_plane_with_margin_dp.at(0), &out_plane_with_margin_dp.at(0)</unsigned></const>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
ref, ref_mode, real_radius, sigma);
|
|
Toshihiro Shimizu |
890ddd |
} else if ((std::numeric_limits<unsigned short="">::digits == bits) && (std::numeric_limits<unsigned short="">::digits == ref_bits)) {</unsigned></unsigned>
|
|
Toshihiro Shimizu |
890ddd |
convert_hv_(
|
|
Toshihiro Shimizu |
890ddd |
static_cast<const *="" short="" unsigned="">(in_with_margin), static_cast<unsigned *="" short="">(out_no_margin), height_with_margin, width_with_margin, channels, &filter_buf.at(0), int_radius, &in_plane_with_margin_dp.at(0), &out_plane_with_margin_dp.at(0)</unsigned></const>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
reinterpret_cast<const *="" short="" unsigned="">(ref), ref_mode, real_radius, sigma);</const>
|
|
Toshihiro Shimizu |
890ddd |
} else if ((std::numeric_limits<unsigned char="">::digits == bits) && (std::numeric_limits<unsigned short="">::digits == ref_bits)) {</unsigned></unsigned>
|
|
Toshihiro Shimizu |
890ddd |
convert_hv_(
|
|
Toshihiro Shimizu |
890ddd |
static_cast<const *="" short="" unsigned="">(in_with_margin), static_cast<unsigned *="" short="">(out_no_margin), height_with_margin, width_with_margin, channels, &filter_buf.at(0), int_radius, &in_plane_with_margin_dp.at(0), &out_plane_with_margin_dp.at(0)</unsigned></const>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
reinterpret_cast<const *="" char="" unsigned="">(ref), ref_mode, real_radius, sigma);</const>
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error("Bad bits,Not uchar/ushort");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|