-
Notifications
You must be signed in to change notification settings - Fork 8
WIP: Image filter options #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hiroyuki-sato
wants to merge
19
commits into
red-data-tools:master
Choose a base branch
from
hiroyuki-sato:topic/image-filter-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4ee338e
wip: implementing median_blur and split
hiroyuki-sato d0ecaef
Apply kou review
hiroyuki-sato c4e7a06
Implement median_blur
hiroyuki-sato 20e303e
Add GCV_IMAGE_FILTER comment
hiroyuki-sato 7eb9c43
Check image filter error message
hiroyuki-sato 488b126
Remove unrelated blank line
hiroyuki-sato c2a0815
Add image_filtering_options
hiroyuki-sato b686f18
wip
hiroyuki-sato 5272221
Add image_filtering_options
hiroyuki-sato 5ca4cfa
wip
hiroyuki-sato 1942609
Apply kou's review
hiroyuki-sato 67f3703
wip
hiroyuki-sato 3a50f21
Laplacian
hiroyuki-sato 4c72950
Add more filters
hiroyuki-sato f7ced6a
Fix BorderType value
hiroyuki-sato e66cc93
Add getDerivKernels
hiroyuki-sato 9783a6c
Fix normalize test
hiroyuki-sato 9b2cb32
Merge branch 'topic/image-filter-options' of github.com:hiroyuki-sato…
hiroyuki-sato fe1ff70
Rename image_filtering -> image_filter
hiroyuki-sato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,274 @@ gcv_drawing_options_new(void) | |
return GCV_DRAWING_OPTIONS(g_object_new(GCV_TYPE_DRAWING_OPTIONS, NULL)); | ||
} | ||
|
||
/*************************************/ | ||
|
||
typedef struct { | ||
gboolean normalize; | ||
// const Scalar &borderValue=morphologyDefaultBorderValue() | ||
// const Size &dstsize=Size() | ||
gdouble delta; | ||
gdouble psi; | ||
gdouble scale; | ||
gdouble sigma_y; | ||
gint border_type; | ||
gint iterations; | ||
gint ksize; | ||
// gint ktype; | ||
gint max_level; | ||
GCVPoint anchor; | ||
// TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) | ||
} GCVImageFilteringOptionsPrivate; | ||
|
||
G_DEFINE_TYPE_WITH_PRIVATE(GCVImageFilteringOptions, | ||
gcv_image_filtering_options, | ||
G_TYPE_OBJECT) | ||
|
||
#define GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object) \ | ||
static_cast<GCVImageFilteringOptionsPrivate *>( \ | ||
gcv_image_filtering_options_get_instance_private( \ | ||
GCV_IMAGE_FILTERING_OPTIONS(object))) | ||
|
||
// TODO | ||
enum { | ||
PROP_NORMALIZE = 1, | ||
PROP_BORDER_VALUE, | ||
PROP_DSTSIZE, | ||
PROP_DELTA, | ||
PROP_PSI, | ||
PROP_SCALE, | ||
PROP_SIGMA_Y, | ||
PROP_BORDER_TYPE, | ||
PROP_ITERATIONS, | ||
PROP_KSIZE, | ||
PROP_KTYPE, | ||
PROP_MAX_LEVEL, | ||
PROP_ANCHOR, | ||
}; | ||
|
||
static void | ||
gcv_image_filtering_options_get_property(GObject *object, | ||
guint prop_id, | ||
GValue *value, | ||
GParamSpec *pspec) | ||
{ | ||
auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); | ||
|
||
switch (prop_id) { | ||
case PROP_NORMALIZE: | ||
g_value_set_boolean(value, priv->normalize); | ||
break; | ||
/* TODO | ||
case PROP_BORDER_VALUE: | ||
g_value_set_XXX(value, priv->border_value); | ||
break; | ||
case PROP_DSTSIZE: | ||
g_value_set_XXX(value, priv->dstsize); | ||
break; | ||
*/ | ||
case PROP_DELTA: | ||
g_value_set_double(value, priv->delta); | ||
break; | ||
case PROP_PSI: | ||
g_value_set_double(value, priv->psi); | ||
break; | ||
case PROP_SCALE: | ||
g_value_set_double(value, priv->scale); | ||
break; | ||
case PROP_SIGMA_Y: | ||
g_value_set_double(value, priv->sigma_y); | ||
break; | ||
case PROP_BORDER_TYPE: | ||
g_value_set_enum(value, priv->border_type); | ||
break; | ||
case PROP_ITERATIONS: | ||
g_value_set_int(value, priv->iterations); | ||
break; | ||
case PROP_KSIZE: | ||
g_value_set_int(value, priv->ksize); | ||
break; | ||
/* | ||
case PROP_KTYPE: | ||
g_value_set_int(value, priv->ktype); | ||
break; | ||
*/ | ||
case PROP_MAX_LEVEL: | ||
g_value_set_int(value, priv->max_level); | ||
break; | ||
/* | ||
case PROP_ANCHOR: | ||
g_value_set_XXX(value, priv->anchor); | ||
break; | ||
*/ | ||
default: | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); | ||
break; | ||
} | ||
|
||
} | ||
|
||
static void | ||
gcv_image_filtering_options_set_property(GObject *object, | ||
guint prop_id, | ||
const GValue *value, | ||
GParamSpec *pspec) | ||
{ | ||
auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); | ||
|
||
switch (prop_id) { | ||
case PROP_NORMALIZE: | ||
priv->normalize = g_value_get_boolean(value); | ||
break; | ||
/* TODO | ||
case PROP_BORDER_VALUE: | ||
priv->border_value = g_value_get_XXX(value); | ||
break; | ||
case PROP_DSTSIZE: | ||
priv->dstsize = g_value_get_XXX(value); | ||
break; | ||
*/ | ||
case PROP_DELTA: | ||
priv->delta = g_value_get_double(value); | ||
break; | ||
case PROP_PSI: | ||
priv->psi = g_value_get_double(value); | ||
break; | ||
case PROP_SCALE: | ||
priv->scale = g_value_get_double(value); | ||
break; | ||
case PROP_SIGMA_Y: | ||
priv->sigma_y = g_value_get_double(value); | ||
break; | ||
case PROP_BORDER_TYPE: | ||
priv->border_type = static_cast<GCVBorderType>(g_value_get_enum(value)); | ||
break; | ||
case PROP_ITERATIONS: | ||
priv->iterations = g_value_get_int(value); | ||
break; | ||
case PROP_KSIZE: | ||
priv->ksize = g_value_get_int(value); | ||
break; | ||
/* | ||
case PROP_KTYPE: | ||
priv->ktype = g_value_get_int(value); | ||
break; | ||
*/ | ||
case PROP_MAX_LEVEL: | ||
priv->max_level = g_value_get_int(value); | ||
break; | ||
/* | ||
case PROP_ANCHOR: | ||
priv->anchor = g_value_get_XXX(value); | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this part, I would like to implement the following. options = CV::ImageFilteringOptions.new
options.anchor = CV::Point.new(-1,-1)
#...
options.anchor |
||
*/ | ||
default: | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); | ||
break; | ||
} | ||
} | ||
|
||
|
||
static void | ||
gcv_image_filtering_options_init(GCVImageFilteringOptions *object) | ||
{ | ||
} | ||
|
||
static void | ||
gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) | ||
{ | ||
GParamSpec *spec; | ||
|
||
auto gobject_class = G_OBJECT_CLASS(klass); | ||
|
||
gobject_class->get_property = gcv_image_filtering_options_get_property; | ||
gobject_class->set_property = gcv_image_filtering_options_set_property; | ||
|
||
spec = g_param_spec_double("delta", | ||
"Delta", | ||
"Delta TODO", | ||
0, G_MAXDOUBLE, 0, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_DELTA, spec); | ||
|
||
/* | ||
spec = g_param_spec_double("psi", | ||
"Psi", | ||
"PSI TODO", | ||
0, G_MAXDOUBLE, cv::CV_PI * 0.5, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_PSI, spec); | ||
*/ | ||
|
||
spec = g_param_spec_double("scale", | ||
"Scale", | ||
"Scale TODO", | ||
0, G_MAXDOUBLE, 1.0, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_SCALE, spec); | ||
|
||
spec = g_param_spec_double("sigmaY", | ||
"Sigma Y", | ||
"sigmaY TODO", | ||
0, G_MAXDOUBLE, 0.0, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_SIGMA_Y, spec); | ||
|
||
spec = g_param_spec_enum("border-type", | ||
"Border type", | ||
"The type of border to be filter", | ||
GCV_TYPE_BORDER_TYPE, | ||
GCV_BORDER_TYPE_BORDER_DEFAULT, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_BORDER_TYPE, spec); | ||
|
||
spec = g_param_spec_int("iterations", | ||
"Iterations", | ||
"The number of iterations", | ||
0, G_MAXINT, 1, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_ITERATIONS, spec); | ||
|
||
spec = g_param_spec_int("ksize", | ||
"Ksize", | ||
"KSize", // TODO | ||
0, G_MAXINT, 1, // TODO | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_KSIZE, spec); | ||
|
||
spec = g_param_spec_int("max-level", | ||
"Max Level", | ||
"Max Level", // TODO | ||
0, G_MAXINT, 1, | ||
static_cast<GParamFlags>(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT)); | ||
g_object_class_install_property(gobject_class, PROP_MAX_LEVEL, spec); | ||
|
||
|
||
} | ||
|
||
/** | ||
* gcv_image_filtering_options_new: | ||
* | ||
* Returns a newly created #GCVImageFilteringOptions. | ||
* | ||
* Since: 1.0.2 | ||
*/ | ||
GCVImageFilteringOptions * | ||
gcv_image_filtering_options_new(void) | ||
{ | ||
return GCV_IMAGE_FILTERING_OPTIONS(g_object_new(GCV_TYPE_IMAGE_FILTERING_OPTIONS, | ||
NULL)); | ||
} | ||
|
||
/***************************** end *******************/ | ||
|
||
G_DEFINE_TYPE(GCVImage, gcv_image, GCV_TYPE_MATRIX) | ||
|
||
static void | ||
|
@@ -722,6 +990,40 @@ GCVImage *gcv_image_median_blur(GCVImage *image, | |
return gcv_image_new_raw(&cv_converted_image); | ||
} | ||
|
||
/** | ||
* gcv_image_blur: | ||
* @image: A #GCVImage. | ||
* @ksize: A #GCVSize blurring kernel size. | ||
* @options: (nullable): A #GCVImageFilteringOptions; | ||
* @error: (nullable): Return locatipcn for a #GError or %NULL. | ||
* | ||
* It effects blur image. The converted image is returned as | ||
* a new image. | ||
* | ||
* Returns: (transfer full): A converted #GCVImage. | ||
* | ||
* Since: 1.0.4 | ||
*/ | ||
GCVImage *gcv_image_blur(GCVImage *image, | ||
GCVSize *ksize, | ||
GCVImageFilteringOptions *options, | ||
GError **error) | ||
{ | ||
auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); | ||
auto cv_ksize = gcv_size_get_raw(ksize); | ||
auto cv_converted_image = std::make_shared<cv::Mat>(); | ||
|
||
if ( options != NULL ) { | ||
auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); | ||
|
||
cv::blur(*cv_image, *cv_converted_image, *cv_ksize, NULL, options_priv->border_type); | ||
} else { | ||
cv::blur(*cv_image, *cv_converted_image, *cv_ksize); | ||
} | ||
|
||
return gcv_image_new_raw(&cv_converted_image); | ||
} | ||
|
||
G_END_DECLS | ||
|
||
GCVImage * | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this part, I would like to implement the following.
Could you advise for that?
(Thank you for helping me. I'm not familiar with C++ pointers, by the way.)