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:
Edward Hervey 2020-12-02 11:29:08 +01:00 committed by Edward Hervey
parent aa68d03013
commit d137171f03
3 changed files with 112 additions and 7 deletions

View file

@ -213020,6 +213020,20 @@
} }
}, },
"properties": { "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": { "method": {
"blurb": "Retinex method to use", "blurb": "Retinex method to use",
"conditionally-available": false, "conditionally-available": false,
@ -213032,6 +213046,20 @@
"type": "GstRetinexMethod", "type": "GstRetinexMethod",
"writable": true "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": { "scales": {
"blurb": "Amount of gaussian filters (scales) used in multiscale retinex", "blurb": "Amount of gaussian filters (scales) used in multiscale retinex",
"conditionally-available": false, "conditionally-available": false,
@ -213045,6 +213073,20 @@
"readable": true, "readable": true,
"type": "gint", "type": "gint",
"writable": true "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" "rank": "none"

View file

@ -79,7 +79,10 @@ enum
{ {
PROP_0, PROP_0,
PROP_METHOD, PROP_METHOD,
PROP_SCALES PROP_SCALES,
PROP_SIGMA,
PROP_GAIN,
PROP_OFFSET,
}; };
typedef enum typedef enum
{ {
@ -89,6 +92,9 @@ typedef enum
#define DEFAULT_METHOD METHOD_BASIC #define DEFAULT_METHOD METHOD_BASIC
#define DEFAULT_SCALES 3 #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 ()) #define GST_TYPE_RETINEX_METHOD (gst_retinex_method_get_type ())
static GType static GType
@ -160,6 +166,42 @@ gst_retinex_class_init (GstRetinexClass * klass)
4, DEFAULT_SCALES, 4, DEFAULT_SCALES,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); (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, gst_element_class_set_static_metadata (element_class,
"Retinex image colour enhancement", "Filter/Effect/Video", "Retinex image colour enhancement", "Filter/Effect/Video",
"Multiscale retinex for colour image enhancement", "Multiscale retinex for colour image enhancement",
@ -182,6 +224,9 @@ gst_retinex_init (GstRetinex * filter)
filter->method = DEFAULT_METHOD; filter->method = DEFAULT_METHOD;
filter->scales = DEFAULT_SCALES; filter->scales = DEFAULT_SCALES;
filter->current_scales = 0; 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), gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
TRUE); TRUE);
} }
@ -217,6 +262,15 @@ gst_retinex_set_property (GObject * object, guint prop_id,
case PROP_SCALES: case PROP_SCALES:
retinex->scales = g_value_get_int (value); retinex->scales = g_value_get_int (value);
break; 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: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -236,6 +290,15 @@ gst_retinex_get_property (GObject * object, guint prop_id,
case PROP_SCALES: case PROP_SCALES:
g_value_set_int (value, filter->scales); g_value_set_int (value, filter->scales);
break; 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: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -265,9 +328,6 @@ gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
Mat img) Mat img)
{ {
GstRetinex *retinex = GST_RETINEX (filter); GstRetinex *retinex = GST_RETINEX (filter);
double sigma = 14.0;
int gain = 128;
int offset = 128;
int filter_size; int filter_size;
/* Basic retinex restoration. The image and a filtered image are converted /* 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); log (retinex->cvA, retinex->cvB);
/* Compute log of blurred image */ /* 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; filter_size = filter_size * 2 + 1;
img.convertTo (retinex->cvD, retinex->cvD.type ()); 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); subtract (retinex->cvB, retinex->cvC, retinex->cvA);
/* Restore */ /* 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 /* 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 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 */ /* 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; return GST_FLOW_OK;

View file

@ -72,6 +72,9 @@ struct _GstRetinex
double *weights; double *weights;
double *sigmas; double *sigmas;
double sigma;
int gain, offset;
cv::Mat cvA; cv::Mat cvA;
cv::Mat cvB; cv::Mat cvB;
cv::Mat cvC; cv::Mat cvC;