def _get_png_info(**kw): """\ Returns the width, height and the pixels of the provided PNG file. """ reader = PNGReader(**kw) w, h, pixels, meta = reader.asDirect() return w, h, _make_pixel_array(pixels, meta['greyscale'])
def one_channel_image_reader(filepath, datatype, input_has_three_channels=True): """Labels are stored in a crude way into the png format that cannot be handled by standard libraries. Therefore, we have to create this decoder.""" im = Reader(filepath) _, _, array, _ = im.asDirect() array = np.vstack(itertools.imap(datatype, array)) if input_has_three_channels: # This image array is now in 'boxed row flat pixel' format, meaning that each row # is just a continuous list of R, G, B, R, G, B, R, ... values. # We are in this case only interested in the first component, which holds the # class label, therefore we take every third value. array = array[:, range(0, array.shape[1], 3)] return datatype(array)