Rollback of https://github.com/tensorflow/tensorflow/pull/41472. The change introduces regression. Reason is that, with the change, the decoder treats number of channels as an indicator for deciding whether to decode png images as palette based or not; if desired channel is 1, then it would decode in palette mode, it not then in rgb mode. However, this fails for grascale rgb images where there exists only 1 channel and don't want palette mode.
PiperOrigin-RevId: 330994095 Change-Id: I1e3f20266fd6d575dfa31ed736e04a1a8064ce93
This commit is contained in:
parent
896635c9cb
commit
3db52f724a
@ -282,11 +282,8 @@ bool CommonInitDecode(StringPiece png_string, int desired_channels,
|
||||
}
|
||||
|
||||
// convert palette to rgb(a) if needs be.
|
||||
// Note if desired_channels=1 then the original palette indices
|
||||
// will be presented.
|
||||
if (context->color_type == PNG_COLOR_TYPE_PALETTE && desired_channels != 1) {
|
||||
if (context->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_palette_to_rgb(context->png_ptr);
|
||||
}
|
||||
|
||||
// handle grayscale case for source or destination
|
||||
const bool want_gray = (context->channels < 3);
|
||||
@ -297,9 +294,7 @@ bool CommonInitDecode(StringPiece png_string, int desired_channels,
|
||||
}
|
||||
}
|
||||
if (want_gray) { // output is grayscale
|
||||
// Note if color type is palette and context->channels < 3,
|
||||
// then the original palette indices will be presented.
|
||||
if (!is_gray && context->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
if (!is_gray)
|
||||
png_set_rgb_to_gray(context->png_ptr, 1, 0.299, 0.587); // 601, JPG
|
||||
} else { // output is rgb(a)
|
||||
if (is_gray)
|
||||
|
@ -4406,17 +4406,6 @@ class PngTest(test_util.TensorFlowTestCase):
|
||||
self.assertEqual(image.get_shape().as_list(),
|
||||
[None, None, channels or None])
|
||||
|
||||
def testPaletteOnly(self):
|
||||
filename = "tensorflow/core/lib/png/testdata/palette_only.png"
|
||||
expected = np.zeros((20, 20, 1), np.uint8)
|
||||
expected[1, 1:19, :] = 1
|
||||
expected[3, 1:19, :] = 2
|
||||
with self.cached_session(use_gpu=True):
|
||||
channels = 1
|
||||
png = image_ops.decode_png(io_ops.read_file(filename), channels=channels)
|
||||
png = self.evaluate(png)
|
||||
self.assertAllEqual(expected, png)
|
||||
|
||||
|
||||
class GifTest(test_util.TensorFlowTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user