After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 433251 - Despeckle producing strange results
Despeckle producing strange results
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
2.3.x
Other All
: Normal minor
: 2.4
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2007-04-25 09:13 UTC by Andrew McMillan
Modified: 2008-01-15 14:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Restores 2.2 behavior (4.89 KB, patch)
2007-05-02 22:53 UTC, geert jordaens
none Details | Review
Despeckle plug-in improved recursive / edge handling (4.66 KB, patch)
2007-05-03 20:17 UTC, geert jordaens
committed Details | Review

Description Andrew McMillan 2007-04-25 09:13:47 UTC
Please describe the problem:
The "Despeckle" filter seems to be producing unexpected results, as follows:

1) Using the "Adaptive" option appears to make the filter do nothing

2) Using the "Recursive" option appears to "smear" the image out of all recognition.

Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?
Without checking the "Adaptive" and "Recursive" options the filter appears to work as one would expect.

Other information:
This is using Debian Sid.  I'm happy to supply sample results if this problem is unusual in any way.
Comment 1 Sven Neumann 2007-04-25 10:21:56 UTC
The algorithm could definitely be improved. But I don't follow all your observations. The plug-in does things, even with the "Adaptive" option checked. The behavior with "Recursive" checked is however somewhat unexpected.
Comment 2 Sven Neumann 2007-04-25 10:37:26 UTC
Recursive also seems to work reasonably for larger radii.
Comment 3 Andrew McMillan 2007-04-26 02:32:15 UTC
OK.  I'll allow that Adaptive might be working (the radius setting doesn't appear to have much effect on it but maybe that's normal).

Recursive, however, seems to produce no usable results for me even with the radius set to 20 (the maximum available in the normal interface).  I just tried it here on an untouched image from my camera and ended up with everything basically smeared rightwards & downwards.

This tutorial here:
http://www.gimpguru.org/Tutorials/RemovingHotPixels/
shows quite different effects using a radius of only 3.

Would you like me to attach any samples, or do any further debugging of the problem?
Comment 4 Sven Neumann 2007-04-26 06:52:01 UTC
Since I very much doubt that we will find time to debug this, any further debugging will be very much appreciated. Note that the algorithm has been changed since GIMP 2.2. It is thus not surprising that the tutorial shows different results.
Comment 5 geert jordaens 2007-05-02 08:26:02 UTC
Referring to Comment #26 from bug #72862  

To summarize. When using the white and black values one influences the
median filter. 

-With highly saturated images the white level should not be chopped off
becaus it will have a big influence on the image however one can safely
chop off with the black level since this would not make a big difference.

-Mostly white images : stay of the white level (set it to 256)
If dark spots have to be removed one can play around with the black level.

-Mostly black images : stay of the black level. (set it to -1)
If white spots have to be removed one can play with the white level.

The possibility of setting the values to -1 and 256 was removed in a more recent patch.

The correct implementation in my opinion should be allow the black / white level correction on a individually.

Right now I don't have the tme to followup a bug report or create a complete patch. However the problem according to me is that the else statement is not executed correctly. 

Things to fix :

1. The else statement should always be executed if filter adaptive is not set.
2. Black and White leves correction should be chosen on rules above.

          for (v = ymin; v < ymax; v++)
            {
              gint off2 = v * width * bpp;

              for (u = xmin, off2 += xmin * bpp; u < xmax; u++, off2 += bpp)
                {
                  guchar value = pixel_luminance (src + off2, bpp);
/* Only correct histogram if filter adaptive is set cannot be less
   than 0 so setting black-level to -1 should disable this correction.
*/
                  if (filter_type & FILTER_ADAPTIVE && value < black_level)
                    {
                      hist0++;
                    }
/* Only correct histogram if filter adaptive is set value cannot be greater
   than 255 so setting white-level to 256 should disable this correction.
*/
                  if (filter_type & FILTER_ADAPTIVE && value > white_level)
                    {
                      hist255++;
                    }
/* If the adaptive filter is active only consider pixels having
   a value between black and white level.
   The new value will be the median of the values in ibuf.
*/
                  if ( !(filter_type & FILTER_ADAPTIVE && value > white_level)||
                       !(filter_type & FILTER_ADAPTIVE && value < black_level)||
                     )
                    {
                      buf[count]  = src + off2;
                      ibuf[count] = value;
                      count++;
                    }
                }
            }



Comment 6 geert jordaens 2007-05-02 22:53:42 UTC
Created attachment 87417 [details] [review]
Restores 2.2 behavior 

Patch that restores 2.2 behavior, gui changes +2.2 are included.

- known issue : 
- Does not work well on small images  < 2 * radius + 1.
  Then again who needs a despeckle plugin for such a image the bad pixels can be   hand picked.
- Borders are not despeckled (radius).
Comment 7 Sven Neumann 2007-05-03 06:19:33 UTC
Setting on milestone 2.4 so we don't forget to do something about what looks like a regression.

Geert, can you explain shortly what your patch does?
Comment 8 geert jordaens 2007-05-03 06:47:01 UTC
Pleas do not yet apply the patch, yesterday evening I already had a 20h day, there the adaptation of the radius should still be fixed.

basicly, I merged the latest version of the despeckle plugin and the version of 2.2 that I worked on. 

The main changes are in : 

- The parameter "black" can be set to -1 : 
  -1 disables the histogram correction on the black side.

- The parameter "white" can be set to 256 : 
  256 disables the histogram correction on the white side.

- Used function despeckle_median from 2.2 version and modified it.
  The main difference is that the histogram correction is handled correctly.
  Only values between black and white level are selected for determining the
  median.

- The adaptation of the radius is not yet correct. Should be as below. 
  (REGRESSION !!!)
                          if (value <= black_level)
                            hist0++;

                          if (value =< white_level)
                            hist255++;

- Border handling is different for 2.2 and latest version.
 (REGRESSION !!!)
 

Comment 9 geert jordaens 2007-05-03 20:17:08 UTC
Created attachment 87484 [details] [review]
Despeckle plug-in improved recursive / edge handling  

Patch should be ready now for general acceptance.

basicly, I merged the latest version of the despeckle plugin and the version of
2.2 that I worked on. 

The main changes are in : 

- The parameter "black" can be set to -1 : 
  -1 disables the histogram correction on the black side.
- The parameter "white" can be set to 256 : 
  256 disables the histogram correction on the white side.
- Used function despeckle_median from 2.2 version and modified it.
  The main difference is that the histogram correction is handled correctly.
  Only values between black and white level are selected for determining the
  median.
- The adaptation of the radius is corrected. 
- Border handling is different as in current version.
Comment 10 Sven Neumann 2007-05-03 20:52:13 UTC
Thanks a lot for that patch. Works much better now.

2007-05-03  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/despeckle.c: applied patch from Geert Jordaens
	plus some minor cleanups. Fixes bug #433251.