mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
opencv: Expose retinex parameters
Makes the plugin a tad more useful :) Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1845>
This commit is contained in:
parent
aa68d03013
commit
d137171f03
3 changed files with 112 additions and 7 deletions
|
@ -213020,6 +213020,20 @@
|
|||
}
|
||||
},
|
||||
"properties": {
|
||||
"gain": {
|
||||
"blurb": "Gain",
|
||||
"conditionally-available": false,
|
||||
"construct": false,
|
||||
"construct-only": false,
|
||||
"controllable": false,
|
||||
"default": "128",
|
||||
"max": "2147483647",
|
||||
"min": "0",
|
||||
"mutable": "null",
|
||||
"readable": true,
|
||||
"type": "gint",
|
||||
"writable": true
|
||||
},
|
||||
"method": {
|
||||
"blurb": "Retinex method to use",
|
||||
"conditionally-available": false,
|
||||
|
@ -213032,6 +213046,20 @@
|
|||
"type": "GstRetinexMethod",
|
||||
"writable": true
|
||||
},
|
||||
"offset": {
|
||||
"blurb": "Offset",
|
||||
"conditionally-available": false,
|
||||
"construct": false,
|
||||
"construct-only": false,
|
||||
"controllable": false,
|
||||
"default": "128",
|
||||
"max": "2147483647",
|
||||
"min": "0",
|
||||
"mutable": "null",
|
||||
"readable": true,
|
||||
"type": "gint",
|
||||
"writable": true
|
||||
},
|
||||
"scales": {
|
||||
"blurb": "Amount of gaussian filters (scales) used in multiscale retinex",
|
||||
"conditionally-available": false,
|
||||
|
@ -213045,6 +213073,20 @@
|
|||
"readable": true,
|
||||
"type": "gint",
|
||||
"writable": true
|
||||
},
|
||||
"sigma": {
|
||||
"blurb": "Sigma",
|
||||
"conditionally-available": false,
|
||||
"construct": false,
|
||||
"construct-only": false,
|
||||
"controllable": false,
|
||||
"default": "14",
|
||||
"max": "1.79769e+308",
|
||||
"min": "0",
|
||||
"mutable": "null",
|
||||
"readable": true,
|
||||
"type": "gdouble",
|
||||
"writable": true
|
||||
}
|
||||
},
|
||||
"rank": "none"
|
||||
|
|
|
@ -79,7 +79,10 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_METHOD,
|
||||
PROP_SCALES
|
||||
PROP_SCALES,
|
||||
PROP_SIGMA,
|
||||
PROP_GAIN,
|
||||
PROP_OFFSET,
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
|
@ -89,6 +92,9 @@ typedef enum
|
|||
|
||||
#define DEFAULT_METHOD METHOD_BASIC
|
||||
#define DEFAULT_SCALES 3
|
||||
#define DEFAULT_SIGMA 14.0
|
||||
#define DEFAULT_GAIN 128
|
||||
#define DEFAULT_OFFSET 128
|
||||
|
||||
#define GST_TYPE_RETINEX_METHOD (gst_retinex_method_get_type ())
|
||||
static GType
|
||||
|
@ -160,6 +166,42 @@ gst_retinex_class_init (GstRetinexClass * klass)
|
|||
4, DEFAULT_SCALES,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
/**
|
||||
* GstRetinex:sigma:
|
||||
*
|
||||
* Sigma
|
||||
*
|
||||
* Since: 1.20
|
||||
*/
|
||||
g_object_class_install_property (gobject_class, PROP_SIGMA,
|
||||
g_param_spec_double ("sigma", "Sigma",
|
||||
"Sigma", 0.0, G_MAXDOUBLE, DEFAULT_SIGMA,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
/**
|
||||
* GstRetinex:gain:
|
||||
*
|
||||
* Gain
|
||||
*
|
||||
* Since: 1.20
|
||||
*/
|
||||
g_object_class_install_property (gobject_class, PROP_GAIN,
|
||||
g_param_spec_int ("gain", "gain",
|
||||
"Gain", 0, G_MAXINT, DEFAULT_GAIN,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
/**
|
||||
* GstRetinex:offset:
|
||||
*
|
||||
* Offset
|
||||
*
|
||||
* Since: 1.20
|
||||
*/
|
||||
g_object_class_install_property (gobject_class, PROP_OFFSET,
|
||||
g_param_spec_int ("offset", "Offset",
|
||||
"Offset", 0, G_MAXINT, DEFAULT_OFFSET,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
gst_element_class_set_static_metadata (element_class,
|
||||
"Retinex image colour enhancement", "Filter/Effect/Video",
|
||||
"Multiscale retinex for colour image enhancement",
|
||||
|
@ -182,6 +224,9 @@ gst_retinex_init (GstRetinex * filter)
|
|||
filter->method = DEFAULT_METHOD;
|
||||
filter->scales = DEFAULT_SCALES;
|
||||
filter->current_scales = 0;
|
||||
filter->gain = DEFAULT_GAIN;
|
||||
filter->offset = DEFAULT_OFFSET;
|
||||
filter->sigma = DEFAULT_SIGMA;
|
||||
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
|
||||
TRUE);
|
||||
}
|
||||
|
@ -217,6 +262,15 @@ gst_retinex_set_property (GObject * object, guint prop_id,
|
|||
case PROP_SCALES:
|
||||
retinex->scales = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_SIGMA:
|
||||
retinex->sigma = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_GAIN:
|
||||
retinex->gain = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_OFFSET:
|
||||
retinex->offset = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -236,6 +290,15 @@ gst_retinex_get_property (GObject * object, guint prop_id,
|
|||
case PROP_SCALES:
|
||||
g_value_set_int (value, filter->scales);
|
||||
break;
|
||||
case PROP_SIGMA:
|
||||
g_value_set_double (value, filter->sigma);
|
||||
break;
|
||||
case PROP_GAIN:
|
||||
g_value_set_int (value, filter->gain);
|
||||
break;
|
||||
case PROP_OFFSET:
|
||||
g_value_set_int (value, filter->offset);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -265,9 +328,6 @@ gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
|
|||
Mat img)
|
||||
{
|
||||
GstRetinex *retinex = GST_RETINEX (filter);
|
||||
double sigma = 14.0;
|
||||
int gain = 128;
|
||||
int offset = 128;
|
||||
int filter_size;
|
||||
|
||||
/* Basic retinex restoration. The image and a filtered image are converted
|
||||
|
@ -280,7 +340,7 @@ gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
|
|||
log (retinex->cvA, retinex->cvB);
|
||||
|
||||
/* Compute log of blurred image */
|
||||
filter_size = (int) floor (sigma * 6) / 2;
|
||||
filter_size = (int) floor (retinex->sigma * 6) / 2;
|
||||
filter_size = filter_size * 2 + 1;
|
||||
|
||||
img.convertTo (retinex->cvD, retinex->cvD.type ());
|
||||
|
@ -292,7 +352,7 @@ gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
|
|||
subtract (retinex->cvB, retinex->cvC, retinex->cvA);
|
||||
|
||||
/* Restore */
|
||||
retinex->cvA.convertTo (img, img.type (), (float) gain, (float) offset);
|
||||
retinex->cvA.convertTo (img, img.type (), (float) retinex->gain, (float) retinex->offset);
|
||||
}
|
||||
/* Multiscale retinex restoration. The image and a set of filtered images are
|
||||
converted to the log domain and subtracted from the original with some set
|
||||
|
@ -339,7 +399,7 @@ gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
|
|||
}
|
||||
|
||||
/* Restore */
|
||||
retinex->cvB.convertTo (img, img.type (), (float) gain, (float) offset);
|
||||
retinex->cvB.convertTo (img, img.type (), (float) retinex->gain, (float) retinex->offset);
|
||||
}
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
|
|
@ -72,6 +72,9 @@ struct _GstRetinex
|
|||
double *weights;
|
||||
double *sigmas;
|
||||
|
||||
double sigma;
|
||||
int gain, offset;
|
||||
|
||||
cv::Mat cvA;
|
||||
cv::Mat cvB;
|
||||
cv::Mat cvC;
|
||||
|
|
Loading…
Reference in a new issue