9
$\begingroup$

Bug in ImageAdjust introduced in 8.0.4 or earlier and fixed in 11.0

Documentation bug for ImageAdjust introduced in 8 or earlier and fixed in 11.1.0
In version 11.1.0 the first statement under "Properties & Relations" reads as (emphasized words are absent in version 11.0.1): "For grayscale images, ImageAdjust[Image[data]] is equivalent to Image[Rescale[data]]".


A recent thread raised several concerns regarding the Documentation page for ImageAdjust.


The first issue is related to the first statement under the "Properties & Relations" on the Documentation page for ImageAdjust:

ImageAdjust[Image[data]] is equivalent to Image[Rescale[data]].

This statement is incorrect for two reasons:

  1. As george2079 correctly notes, "For color images ImageAdjust works independently on each channel while Rescale applies a single transformation to the whole data array."

  2. Actually even for single-channel images Image[Rescale[data]] produces slightly different image as it is clear from the example provided:

    data = GaborMatrix[100, {.1, .1}];
    res1 = ImageAdjust[Image[data]];
    res2 = Image[Rescale[data]];
    Max[ImageData[res1] - ImageData[res2]]
    
    2.77556*10^-17
    

    From the other hand, if we try to use the code for the second statement under the "Properties & Relations" for the above single-channel image we obtain exactly identical image:

    ImageAdjust[Image[data]] == 
     ImageAdjust[Image[data], {0, 0, 1}, 
      ImageMeasurements[Image[data], {"Min", "Max"}], {0, 1}]
    
    True
    

From the above it is clear that for single-channel images the correct statement should be: "ImageAdjust[Image[data]] is equivalent to ImageAdjust[Image[data], {0, 0, 1}, ImageMeasurements[Image[data], {"Min", "Max"}], {0, 1}]."


The second issue is related to the above-mentioned code for the second statement under the "Properties & Relations". This code simply does not work with the provided color image and produces error (checked with version 10.2 on Windows 7 x64):

screenshot

Does it mean that ImageAdjust does not allow to specify separate range for each channel as george2079 states in the comment? In this case, then we have a bug in the Documentation (see the statement on the above screenshot). An alternative is that we have a bug in ImageAdjust.

What do you think about the first issue? Is it a Documentation bug?

$\endgroup$
4
$\begingroup$

This is interesting. I have two comments that grew too long for the comment box, so I'll post them here instead.

  1. Is it possible that the discrepancy in your point (2) is only due to roundoff error? After all the difference is less than $MachineEpsilon.

  2. I made the following weird discovery: if you calculate the result of the ImageMeasurements expression, then copy the numerical result inside the ImageAdjust expression, it will work; if you leave the ImageMeasurements inside the ImageAdjust, or even if you assign that value to a variable first, it will not work anymore!

Here is what I mean. I am using the image from the docs, which I also uploaded here for convenience:

Mathematica graphics

imgmeas = ImageMeasurements[img, {"Min", "Max"}]
(* Out: {{0.00784314, 0.0627451, 0.117647}, {0.882353, 0.898039, 0.984314}} *)

ImageAdjust[
 img,
 {0, 0, 1},
 {{0.00784314, 0.0627451, 0.117647}, {0.882353, 0.898039, 0.984314}},
 {0, 1}
]

ImageMeasurements[%, {"Min", "Max"}]

it worked

(* Out: {{0., 0., 0.}, {1., 1., 1.}} *)

Compare the above to what happens when you use the saved values from imgmeas:

ImageAdjust[
 img,
 {0, 0, 1},
 imgmeas,
 {0, 1}
]

does not work

I'm afraid that I don't have an explanation of what is going on here, unless it's a problem within ImageAdjust. What are we missing?

$\endgroup$
  • 1
    $\begingroup$ Surprisingly, it also works if we pack or unpack the output of ImageMeasurements: ImageAdjust[img, {0, 0, 1}, Developer`ToPackedArray@ImageMeasurements[img, {"Min", "Max"}], {0, 1}] works and ImageAdjust[img, {0, 0, 1}, Developer`FromPackedArray@ImageMeasurements[img, {"Min", "Max"}], {0, 1}] works too! $\endgroup$ – Alexey Popkov Aug 27 '15 at 15:15
  • $\begingroup$ It seems that the reason for the problem is that ImageMeasurements returns a List of packed arrays: Developer`PackedArrayQ /@ ImageMeasurements[img, {"Min", "Max"}] returns {True, True}, while the upper level is not packed: Developer`PackedArrayQ@ImageMeasurements[img, {"Min", "Max"}] returns False. $\endgroup$ – Alexey Popkov Aug 27 '15 at 15:22
  • 1
    $\begingroup$ So another workaround is to apply List on the Level 1 for unpacking the packed lists: ImageAdjust[img, {0, 0, 1}, List @@@ ImageMeasurements[img, {"Min", "Max"}], {0, 1}] works. $\endgroup$ – Alexey Popkov Aug 27 '15 at 15:26
  • 1
    $\begingroup$ I have checked it in version 8.0.4 and it has the same bug in ImageAdjust: ImageAdjust[img,{0,0,1},Developer`ToPackedArray/@{{0.007,0.06,0.1},{0.8,0.8,0.9}},{0,1}] produces the same error as in version 10. $\endgroup$ – Alexey Popkov Aug 27 '15 at 15:35
  • $\begingroup$ For the color image we obtain exactly identical image with the above workaround: ImageAdjust[img]===ImageAdjust[img,{0,0,1},List@@@ImageMeasurements[img,{"Min","Max"}],{0,1}] returns True. So this Documentation statement is correct. $\endgroup$ – Alexey Popkov Aug 27 '15 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.