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 72862 - Incorrect RGBA resampling in Despeckle plug-in
Incorrect RGBA resampling in Despeckle plug-in
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
1.x
Other All
: Normal minor
: Future
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks: 70335
 
 
Reported: 2002-02-27 17:11 UTC by Raphaël Quinet
Modified: 2007-12-11 20:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Attempt to resolve the incorrect RGBA resampling (32.54 KB, text/plain)
2004-05-29 07:59 UTC, geert jordaens
  Details
Patch for RGBA (28.41 KB, patch)
2004-06-03 16:20 UTC, geert jordaens
accepted-commit_now Details | Review
despeckle.c after my cleanups (38.15 KB, text/plain)
2004-06-05 16:02 UTC, Sven Neumann
  Details
Correct patch for RGBA (35.57 KB, patch)
2004-06-05 19:44 UTC, geert jordaens
none Details | Review
geert's patch after some coding style cleanups (37.42 KB, patch)
2004-06-10 12:38 UTC, Sven Neumann
needs-work Details | Review
Strange pixels at the edge (37.54 KB, patch)
2004-06-10 17:44 UTC, geert jordaens
none Details | Review
revised patch (35.02 KB, patch)
2004-06-19 09:31 UTC, geert jordaens
none Details | Review
test image (100.46 KB, image/png)
2004-06-19 09:55 UTC, Sven Neumann
  Details
complete file cvs seems out at the moment (31.23 KB, text/plain)
2004-06-19 12:09 UTC, geert jordaens
  Details
comparison of old and new code (41.00 KB, image/png)
2004-06-19 12:57 UTC, Sven Neumann
  Details
new despeckle algorithm's (44.38 KB, text/plain)
2004-10-06 20:20 UTC, geert jordaens
  Details
Despeckle patch (42.98 KB, patch)
2004-10-15 17:50 UTC, geert jordaens
none Details | Review
Patch with only median filter based on pixel intensity(only). (30.38 KB, patch)
2004-10-26 18:39 UTC, geert jordaens
none Details | Review
Modified according comments (29.65 KB, patch)
2004-10-30 11:55 UTC, geert jordaens
none Details | Review
patch after coding style cleanups (30.37 KB, patch)
2004-10-30 12:54 UTC, Sven Neumann
committed Details | Review

Description Raphaël Quinet 2002-02-27 17:11:00 UTC
If two pixels have different opacity values (alpha channel), then their
colors are not averaged correctly by the Enhance->Despeckle plug-in.  The
preview window of this plug-in is also affected.
It looks like the RGB channels are resampled without taking the opacity
into account.  As a result, the (invisible) color of a transparent pixel
can bleed into an opaque pixel.  The resulting image is incorrect.

See bug #70335 for some test images and a longer description of the
problem.  This problem affects many other tools and plug-ins.
Comment 1 Dave Neary 2003-07-23 16:18:54 UTC
Changed target milestone of several bugs to 2.0 - these are not features, and
don't look to me like blockers for a pre-release, but they have to be addressed
before 2.0.

Dave.
Comment 2 Dave Neary 2003-11-25 12:15:25 UTC
Bumping the milestone for this bug, and all that depend on it, to 2.2.

In the absence of someone actively working on this, there is no point keeping it
on the 2.0 milestone.

If someone wants to work on this, fixes to this family would also be accepted on
the stable branch.

Dave.
Comment 3 geert jordaens 2004-05-25 19:50:07 UTC
I ve been looking at the plug-in and think it is simply not possible to
despeckle a RGBA image correctly.

The thing is that the despeckle algorithm takes the median and not the average
value.

The only possible way is to flatten the image and the despeckle.

So the right thing to do would be change the parameters for the
gimp_install_procedure
Comment 4 geert jordaens 2004-05-29 07:59:02 UTC
Created attachment 28138 [details]
Attempt to resolve the incorrect RGBA resampling

I've added a whole file since it changed drasticly.
Comment 5 Sven Neumann 2004-05-31 10:43:31 UTC
Uhh, how am I supposed to review a whole file? And why doesn't the new file
follow the GIMP coding style?
Comment 6 geert jordaens 2004-05-31 19:28:43 UTC
I didn't supply a patch file since I think it should be tested further.
I was not able to download the files from the tracking bug.
To do more thorrow testing.

Please give me a hint concerning the GIMP coding style.
If I have had the chance to test it more I'll make it follow the
coding style. And I'll provide a patch to minimize your work.
Comment 7 geert jordaens 2004-06-03 16:20:10 UTC
Created attachment 28300 [details] [review]
Patch for RGBA 

Rather a big change. Further all tabs ar also replaced.

Did testing with images from the tracking bug and it seams OK to me.
Comment 8 Sven Neumann 2004-06-03 16:34:03 UTC
Looks good except the C++ style comments. These aren't portable and need to be
replaced when the patch is applied. I will do that later.
Comment 9 Sven Neumann 2004-06-05 16:00:29 UTC
I have done some major cleanup but unfortunately I seem to have broken the
preview mode. I am also having trouble to understand the code you added. Why is
there a despeckle_new() function that is only used for the preview? Or have I
misunderstood your code?

I will attach my version. Perhaps you can review it.
Comment 10 Sven Neumann 2004-06-05 16:02:35 UTC
Created attachment 28370 [details]
despeckle.c after my cleanups

Should even be a little bit faster but the preview doesn't look correct :(
Comment 11 geert jordaens 2004-06-05 17:33:26 UTC
Sven,

i had made a new patch after your comments. I think you used the old one
(complete file).


Patch for RGBA   patch 	2004-06-03 12:20
Comment 12 Sven Neumann 2004-06-05 18:14:08 UTC
I used the latest patch you attached (and yes, it still had C++ style comments).
Anyway, I am not going to go through this cleanup once more. It took me almost
two hours to get the code into a readable state.
Comment 13 geert jordaens 2004-06-05 19:44:48 UTC
Created attachment 28377 [details] [review]
Correct patch for RGBA

Sven,

sorry for the inconvinience, it was the wrong patch.
Now it should also be more clear, only one function for preview and drawing.
Comment 14 Sven Neumann 2004-06-05 20:32:36 UTC
I will need a few days off from this code before I can attempt to merge your and
my changes.
Comment 15 Sven Neumann 2004-06-10 12:38:02 UTC
Created attachment 28548 [details] [review]
geert's patch after some coding style cleanups

I've applied your new patch to my local tree and did some coding style and
whitespace cleanups. Was about to commit it but decided to do some testing and
found that the patched version introduces some very well visible artefacts.
Pure red pixels appeared all over the image. Looks like you patch breaks the
plug-in :(
Comment 16 geert jordaens 2004-06-10 13:15:00 UTC
Didn't see that with the test images I used.
Did you use another one? 

Used it on different of images of my own RGB and GRAY + the RGBA images from 
the tracking bug. 

If you have test case I'll look into it
Comment 17 geert jordaens 2004-06-10 15:28:20 UTC
I ve tried the new patch and indeed I did observe strange cyan pixels near the
edge of my drawing. This happend only in the preview window.
Further more the white level has to be on 256  which is kinda out of range isn't
it? 
Comment 18 geert jordaens 2004-06-10 17:44:55 UTC
Created attachment 28566 [details] [review]
Strange pixels at the edge

The only strange pixels I found where on the edge of the preview and drawing.
So this patch ingores the edges.
Comment 19 geert jordaens 2004-06-11 06:17:41 UTC
woke up this moring drove to work and was thinking:
The patch of yesterday evening does fix(skips) the edge conditions
however where could I possebly make pixels visible. I've found one
possible place.

                /*
                 * Sort pixels and
                 * Assign the median value...
                 */

                switch (valuecount)
                  {
                    case 0:   /* No values within histogram */
-                     *(row_buffer+rowpos) = 255;
+                      if (channel < 3 )
+                        *(row_buffer+rowpos) = 255;
                     break;

This should keep the original alpha value for the pixel. I'll test it when I'm 
back home.

Comment 20 geert jordaens 2004-06-19 09:31:26 UTC
Created attachment 28851 [details] [review]
revised patch

Comments / testcases/images are welcome
Comment 21 Sven Neumann 2004-06-19 09:55:14 UTC
Created attachment 28852 [details]
test image

Here's a test image that shows ugly artefacts when the patched version of
despeckle is run with default arguments. The artefacts already show up in the
preview.
Comment 22 geert jordaens 2004-06-19 12:09:05 UTC
Created attachment 28854 [details]
complete file cvs seems out at the moment

Test image served his purpose well. After the merge of different 
changes the plugin was broken.
Now I think the result is OK.
Comment 23 Sven Neumann 2004-06-19 12:57:32 UTC
Created attachment 28856 [details]
comparison of old and new code

This is better but I am starting to wonder what exactly your patch changes and
why. If you compare the results of Despeckle before and after your changes,
there are quite noticable differences. The old code already introduced wrong
colors at places with high contrast. The new code seems to be worse in this
respect. So why are we changing the plug-in to behave worse?
Comment 24 geert jordaens 2004-06-19 13:12:29 UTC
The improvement is mostly noticable in RGBA images.
However you ar probaly reffering to the pixels turning yellow at the shoulder?

>The old code already introduced wrong
>colors at places with high contrast. 
ahh. The high contrast areas are bound reveal other colors since you
adjusting the histogram (in this case chopping off) shifts the median value.
A possible solution could be adding for each chopped off value either a
value of 0 or 255 to the list. Also with adaptive it is not sure that the
radius is the same for each color this could yeald one pixel having calculated
its median value on 9 pixels while another could have 49 if radius is 3. 
Comment 25 Sven Neumann 2004-06-19 13:38:41 UTC
I am more worried about the very noticeable introduction of magenta.

IMHO this plug-in is mainly used to enhance RGB drawable w/o an alpha channel.
So our main focus should be to obtain the best results for this use case. If it
turns out that fixing the RGBA case causes degradation in the RGB use case, then
IMHO the plug-in should be changed to work only on RGB images.
Comment 26 geert jordaens 2004-06-19 14:21:47 UTC
To summarize. When using the white and black values one influences the
median filter. I don't think this is necessary in most circumstances.
Black and white drawings do benefit from these parameters.

-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.
Comment 27 geert jordaens 2004-10-06 20:20:27 UTC
Created attachment 32304 [details]
new despeckle algorithm's

I've been playing around with some algorithm's for despeckling 
RGB(A) images. This is a test version that I already wanted to share.
Comment 28 geert jordaens 2004-10-15 17:50:17 UTC
Created attachment 32651 [details] [review]
Despeckle patch

Despeckle plugin:
 type median: - quickselect method to determinde median value 
	      - uses median of the intensity for rgb pictures.
	      - like previous versions this does not work (correctly)
		for RGBA or GRAYA.

 type FMVMF  : "Fast Modified Vector Median Filter" although the name 
	       suggests being fast this is a slow algorithm but it can
	       be used for RGB(A) and Gray(A). (internaly limited to a 
	       maximum radius of 2 (5 by 5 kernal))

 type DDF    : "Distance  Directional Filter" can be used for RGB(A) and       
			  
	       GRAY(A). Not so fast also limited to radius 2. This filter      
		     
	       combines the standard VMF (Vector median filter) BVDMF (Basic
	       vector directional median filter) and the TFVMF (Threshold
vector 
	       With threshold also median filter). 
	       - weight parameter weigths the "distance" and "direction" 
		 components of the filter.
	       - threshold can be used to limmit the number of changed pixels
Comment 29 Sven Neumann 2004-10-24 20:47:12 UTC
Geert, do you suggest we apply this patch for 2.2?
Comment 30 geert jordaens 2004-10-25 04:51:26 UTC
Maybe the vector part is to slow although ig gives good result.
The median filter as before is improved but does not work for RGBA.

So I think it could be implemented but I'd like to see som tests by others
before. 
Comment 31 geert jordaens 2004-10-26 18:39:31 UTC
Created attachment 33086 [details] [review]
Patch with only median filter based on pixel intensity(only).

Maybee a patch	containing only the modified median filter (based on pixel
intensity) should only be applied at this moment. 
Therefore I'm attaching this patch.

patch 32651 contains the vector based filters that give a good
result on RGBA images but are very slow this is also new functionality.
Comment 32 Sven Neumann 2004-10-27 19:44:59 UTC
That code would need some cleanup before it can be accepted. There's at least
one C++ style comment (//) and there are K&R style function prototypes
(dialog_adaptive_callback).

Also, would you mind to elaborate what this patch does? If I see it correctly,
it adds a new algorithm to the plug-in. Since this new algorithm has the same
problem as what this bug report is about, this would count as a new feature, right?
Comment 33 geert jordaens 2004-10-27 21:07:36 UTC
The plugin does not introduce new pixelvalues  it selets the median pixel
based on it's intenisty. You'll see the strange colours that poped-up
with the previous versions are gone. Also the quickselect should be able to find 
the medium value faster.

Despeckle plugin:
 type median: - quickselect method to determinde median value 
	      - uses median of the intensity for rgb pictures.
	      - like previous versions this does not work 
		for RGBA or GRAYA (to say : it only takes RGB in account)

I'll try to change those type definitions and the comment asap.
Comment 34 Sven Neumann 2004-10-29 22:41:26 UTC
Waiting for your patch...
Comment 35 geert jordaens 2004-10-30 11:55:54 UTC
Created attachment 33250 [details] [review]
Modified according comments

Modified.
Comment 36 Sven Neumann 2004-10-30 12:36:30 UTC
Don't your idea hurt if you look at this code? Mine surely do. I really can't
understand how you can submit a patch that completely ruins the code formatting
in that file. The rest of the code was all cleaned up and properly indented and
your patch just ignores that code and introduces a completely different and
inconsistent coding style. Anyway, I am cleaning it up now...
Comment 37 Sven Neumann 2004-10-30 12:46:28 UTC
Err, that should have read "Don't your eyes hurt ..."  /me goes to get more
coffee...
Comment 38 Sven Neumann 2004-10-30 12:54:53 UTC
Created attachment 33253 [details] [review]
patch after coding style cleanups
Comment 39 Sven Neumann 2004-10-30 12:57:39 UTC
Applied this version to the HEAD branch. Moving the bug-report from the 2.2
milestone now.

2004-10-30  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/despeckle.c: applied a patch from Geert Jordaens
	that improves the Despeckle algorithm. See bug #72862.

Comment 40 weskaggs 2007-12-11 20:23:19 UTC
I'm going to resolve this as FIXED because it ended with the application of a patch, and isn't worth the pain of reading through at this point.  If there are still problems with the Despeckle plug-in, please open a new bug report to describe them.