opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2013 Miguel Casas-Sanchez <miguelecasassanchez@gmail.com>
|
2015-12-12 20:07:32 +00:00
|
|
|
*
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
|
|
|
* which case the following provisions apply instead of the ones
|
|
|
|
* mentioned above:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-retinex
|
|
|
|
*
|
|
|
|
* Basic and multiscale retinex for colour image enhancement, see article:
|
|
|
|
*
|
2015-12-12 20:07:32 +00:00
|
|
|
* Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex for
|
|
|
|
* color image enhancement." Image Processing, 1996. Proceedings., International
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
* Conference on. Vol. 3. IEEE, 1996.
|
|
|
|
*
|
2019-05-29 20:58:08 +00:00
|
|
|
* ## Example launch line
|
|
|
|
*
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
* |[
|
2018-12-01 21:48:53 +00:00
|
|
|
* gst-launch-1.0 videotestsrc ! videoconvert ! retinex ! videoconvert ! xvimagesink
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
* ]|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstretinex.h"
|
2018-08-02 15:03:47 +00:00
|
|
|
#include <opencv2/imgproc.hpp>
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_retinex_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_retinex_debug
|
|
|
|
|
2015-10-02 17:40:43 +00:00
|
|
|
using namespace cv;
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_METHOD,
|
|
|
|
PROP_SCALES
|
|
|
|
};
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
METHOD_BASIC,
|
|
|
|
METHOD_MULTISCALE
|
|
|
|
} GstRetinexMethod;
|
|
|
|
|
|
|
|
#define DEFAULT_METHOD METHOD_BASIC
|
|
|
|
#define DEFAULT_SCALES 3
|
|
|
|
|
|
|
|
#define GST_TYPE_RETINEX_METHOD (gst_retinex_method_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_retinex_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType etype = 0;
|
|
|
|
if (etype == 0) {
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{METHOD_BASIC, "Basic retinex restoration", "basic"},
|
|
|
|
{METHOD_MULTISCALE, "Mutiscale retinex restoration", "multiscale"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
etype = g_enum_register_static ("GstRetinexMethod", values);
|
|
|
|
}
|
|
|
|
return etype;
|
|
|
|
}
|
|
|
|
|
2016-12-04 03:02:23 +00:00
|
|
|
G_DEFINE_TYPE (GstRetinex, gst_retinex, GST_TYPE_OPENCV_VIDEO_FILTER);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB")));
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB")));
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_retinex_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_retinex_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2016-12-04 03:02:23 +00:00
|
|
|
static GstFlowReturn gst_retinex_transform_ip (GstOpencvVideoFilter * filter,
|
2018-12-01 21:48:53 +00:00
|
|
|
GstBuffer * buff, Mat img);
|
2018-11-25 15:12:40 +00:00
|
|
|
static gboolean gst_retinex_set_caps (GstOpencvVideoFilter * btrans,
|
2018-12-01 21:48:53 +00:00
|
|
|
gint in_width, gint in_height, int in_cv_type,
|
|
|
|
gint out_width, gint out_height, int out_cv_type);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
static void gst_retinex_finalize (GObject * object);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
/* initialize the retinex's class */
|
|
|
|
static void
|
|
|
|
gst_retinex_class_init (GstRetinexClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2016-12-04 03:02:23 +00:00
|
|
|
GstOpencvVideoFilterClass *cvbasefilter_class =
|
|
|
|
(GstOpencvVideoFilterClass *) klass;
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
gobject_class->finalize = gst_retinex_finalize;
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
gobject_class->set_property = gst_retinex_set_property;
|
|
|
|
gobject_class->get_property = gst_retinex_get_property;
|
|
|
|
|
2016-12-04 03:02:23 +00:00
|
|
|
cvbasefilter_class->cv_trans_ip_func = gst_retinex_transform_ip;
|
|
|
|
cvbasefilter_class->cv_set_caps = gst_retinex_set_caps;
|
|
|
|
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_METHOD,
|
|
|
|
g_param_spec_enum ("method",
|
|
|
|
"Retinex method to use",
|
|
|
|
"Retinex method to use",
|
|
|
|
GST_TYPE_RETINEX_METHOD, DEFAULT_METHOD,
|
2015-10-02 17:40:43 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SCALES,
|
|
|
|
g_param_spec_int ("scales", "scales",
|
|
|
|
"Amount of gaussian filters (scales) used in multiscale retinex", 1,
|
2015-10-02 17:40:43 +00:00
|
|
|
4, DEFAULT_SCALES,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2019-09-02 19:08:44 +00:00
|
|
|
"Retinex image colour enhancement", "Filter/Effect/Video",
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
"Multiscale retinex for colour image enhancement",
|
|
|
|
"Miguel Casas-Sanchez <miguelecasassanchez@gmail.com>");
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &src_factory);
|
|
|
|
gst_element_class_add_static_pad_template (element_class, &sink_factory);
|
2020-05-31 07:18:00 +00:00
|
|
|
|
2020-06-05 22:40:42 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_RETINEX_METHOD, (GstPluginAPIFlags) 0);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the new element
|
|
|
|
* instantiate pads and add them to element
|
2019-09-02 19:08:44 +00:00
|
|
|
* set pad callback functions
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
* initialize instance structure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_retinex_init (GstRetinex * filter)
|
|
|
|
{
|
|
|
|
filter->method = DEFAULT_METHOD;
|
|
|
|
filter->scales = DEFAULT_SCALES;
|
|
|
|
filter->current_scales = 0;
|
2015-09-29 19:00:02 +00:00
|
|
|
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
|
|
|
|
TRUE);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
static void
|
|
|
|
gst_retinex_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstRetinex *filter;
|
|
|
|
filter = GST_RETINEX (object);
|
|
|
|
|
|
|
|
filter->cvA.release ();
|
|
|
|
filter->cvB.release ();
|
|
|
|
filter->cvC.release ();
|
|
|
|
filter->cvD.release ();
|
|
|
|
g_free (filter->weights);
|
|
|
|
filter->weights = NULL;
|
|
|
|
g_free (filter->sigmas);
|
|
|
|
filter->sigmas = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_retinex_parent_class)->finalize (object);
|
|
|
|
}
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_retinex_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRetinex *retinex = GST_RETINEX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
|
|
|
retinex->method = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_SCALES:
|
|
|
|
retinex->scales = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_retinex_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRetinex *filter = GST_RETINEX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_METHOD:
|
|
|
|
g_value_set_enum (value, filter->method);
|
|
|
|
break;
|
|
|
|
case PROP_SCALES:
|
|
|
|
g_value_set_int (value, filter->scales);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-11-25 15:12:40 +00:00
|
|
|
gst_retinex_set_caps (GstOpencvVideoFilter * filter, gint in_width,
|
2018-12-01 21:48:53 +00:00
|
|
|
gint in_height, int in_cv_type, gint out_width,
|
|
|
|
gint out_height, int out_cv_type)
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
{
|
2016-12-04 03:02:23 +00:00
|
|
|
GstRetinex *retinex = GST_RETINEX (filter);
|
2018-12-01 21:48:53 +00:00
|
|
|
Size size;
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
size = Size (in_width, in_height);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
retinex->cvA.create (size, CV_32FC3);
|
|
|
|
retinex->cvB.create (size, CV_32FC3);
|
|
|
|
retinex->cvC.create (size, CV_32FC3);
|
|
|
|
retinex->cvD.create (size, CV_32FC3);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-12-04 03:02:23 +00:00
|
|
|
gst_retinex_transform_ip (GstOpencvVideoFilter * filter, GstBuffer * buf,
|
2018-12-01 21:48:53 +00:00
|
|
|
Mat img)
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
{
|
2016-12-04 03:02:23 +00:00
|
|
|
GstRetinex *retinex = GST_RETINEX (filter);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
double sigma = 14.0;
|
|
|
|
int gain = 128;
|
|
|
|
int offset = 128;
|
|
|
|
int filter_size;
|
|
|
|
|
|
|
|
/* Basic retinex restoration. The image and a filtered image are converted
|
|
|
|
to the log domain and subtracted.
|
2015-12-12 20:07:32 +00:00
|
|
|
O = Log(I) - Log(H(I))
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
where O is the output, H is a gaussian 2d filter and I is the input image. */
|
|
|
|
if (METHOD_BASIC == retinex->method) {
|
|
|
|
/* Compute log image */
|
2018-12-01 21:48:53 +00:00
|
|
|
img.convertTo (retinex->cvA, retinex->cvA.type ());
|
|
|
|
log (retinex->cvA, retinex->cvB);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
2019-09-02 19:08:44 +00:00
|
|
|
/* Compute log of blurred image */
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
filter_size = (int) floor (sigma * 6) / 2;
|
|
|
|
filter_size = filter_size * 2 + 1;
|
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
img.convertTo (retinex->cvD, retinex->cvD.type ());
|
|
|
|
GaussianBlur (retinex->cvD, retinex->cvD, Size (filter_size, filter_size),
|
|
|
|
0.0, 0.0);
|
|
|
|
log (retinex->cvD, retinex->cvC);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
/* Compute difference */
|
2018-12-01 21:48:53 +00:00
|
|
|
subtract (retinex->cvB, retinex->cvC, retinex->cvA);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
/* Restore */
|
2018-12-01 21:48:53 +00:00
|
|
|
retinex->cvA.convertTo (img, img.type (), (float) gain, (float) offset);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
}
|
|
|
|
/* 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
|
2019-09-02 19:08:44 +00:00
|
|
|
of weights. Typically called with three equally weighted scales of fine,
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
medium and wide standard deviations.
|
|
|
|
O = Log(I) - sum_i [ wi * Log(H(I)) ]
|
|
|
|
where O is the output, H is a gaussian 2d filter and I is the input image
|
|
|
|
sum_i means summatory on var i with i in [0..scales) and wi are the weights */
|
|
|
|
else if (METHOD_MULTISCALE == retinex->method) {
|
2015-05-27 12:08:46 +00:00
|
|
|
int i;
|
|
|
|
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
/* allocate or reallocate the weights and sigmas according to scales */
|
|
|
|
if (retinex->current_scales != retinex->scales || !retinex->sigmas) {
|
|
|
|
retinex->weights =
|
|
|
|
(double *) g_realloc (retinex->weights,
|
|
|
|
sizeof (double) * retinex->scales);
|
|
|
|
retinex->sigmas =
|
|
|
|
(double *) g_realloc (retinex->sigmas,
|
|
|
|
sizeof (double) * retinex->scales);
|
2015-05-27 12:08:46 +00:00
|
|
|
for (i = 0; i < retinex->scales; i++) {
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
retinex->weights[i] = 1.0 / (double) retinex->scales;
|
|
|
|
retinex->sigmas[i] = 10.0 + 4.0 * (double) retinex->scales;
|
|
|
|
}
|
|
|
|
retinex->current_scales = retinex->scales;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute log image */
|
2018-12-01 21:48:53 +00:00
|
|
|
img.convertTo (retinex->cvA, retinex->cvA.type ());
|
|
|
|
log (retinex->cvA, retinex->cvB);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
/* Filter at each scale */
|
2015-05-27 12:08:46 +00:00
|
|
|
for (i = 0; i < retinex->scales; i++) {
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
filter_size = (int) floor (retinex->sigmas[i] * 6) / 2;
|
|
|
|
filter_size = filter_size * 2 + 1;
|
|
|
|
|
2018-12-01 21:48:53 +00:00
|
|
|
img.convertTo (retinex->cvD, retinex->cvD.type ());
|
|
|
|
GaussianBlur (retinex->cvD, retinex->cvD, Size (filter_size, filter_size),
|
|
|
|
0.0, 0.0);
|
|
|
|
log (retinex->cvD, retinex->cvC);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
|
|
|
|
/* Compute weighted difference */
|
2018-12-01 21:48:53 +00:00
|
|
|
retinex->cvC.convertTo (retinex->cvC, -1, retinex->weights[i], 0.0);
|
|
|
|
subtract (retinex->cvB, retinex->cvC, retinex->cvB);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore */
|
2018-12-01 21:48:53 +00:00
|
|
|
retinex->cvB.convertTo (img, img.type (), (float) gain, (float) offset);
|
opencv: Add colour image enhancement element based on Retinex algorithm
Add colour image enhancement element based on Retinex algorithm. Two types
exist, namely basic and multiscale; both are described in this article:
Rahman, Zia-ur, Daniel J. Jobson, and Glenn A. Woodell. "Multi-scale retinex
for color image enhancement." Image Processing, 1996. Proceedings.,
International Conference on. Vol. 3. IEEE, 1996
Visually speaking the result looks a bit funny, but is pretty invariable to
lightning changes, which is good for some applications, like image
segmentation.
https://bugzilla.gnome.org/show_bug.cgi?id=700977
2013-05-27 09:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry point to initialize the plug-in
|
|
|
|
* initialize the plug-in itself
|
|
|
|
* register the element factories and other features
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_retinex_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
/* debug category for fltering log messages
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_retinex_debug, "retinex",
|
|
|
|
0, "Multiscale retinex for colour image enhancement");
|
|
|
|
|
|
|
|
return gst_element_register (plugin, "retinex", GST_RANK_NONE,
|
|
|
|
GST_TYPE_RETINEX);
|
|
|
|
}
|