[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Base64 String to Image Matrix

From: Mike Miller
Subject: Re: Base64 String to Image Matrix
Date: Tue, 6 Sep 2016 11:30:38 -0700
User-agent: NeoMutt/ (1.7.0)

On Mon, Sep 05, 2016 at 13:15:36 -0700, alex jones wrote:
> I have buit a front end web app that outputs 28x28 pixel RGB images (.png) in
> this base64 format (below is an image of the number 9 - can view image here:
> "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAABkElEQVRIS+2WO46CUBiFDytQFmDUHcAK1B1gRSmlFWpnp5ZWauisdAVCQa3uQFfgawO6gpmcm1yjJnKv4kwmE/6EEGLg4zx+ogHgC784RgZMcrtUKqFYLOJwOGC/32sF85al+Xwei8UC1WpVQM7nszjbtq0EvwRst9uoVCoCROh8PsdsNoPrumg2mwiCAL7vJyrVBo7HY7RaLfGw7XYLwlerlbg+Ho8oFAoYDofodrvpgcxqt9shiiI4jnP3QEKpWlq62WzSA2lbo9FAuVy+y6jf76PX6+F0OgmFhkHDkkfLUpaCSm7VyZdgQ5nn4+/PsEogC7JcLjEYDEBFHILZUlo8nU4RxzE6nQ6Ys2q0gZPJRBSFapjn5XKBZVnwPA+j0Qi1Wu1aoiSoEkgAlzqXy6Ferwt1zFMCZI6maV73MRWQN99Ceb1er69LL4E6heG9SoXybZmlzJCF4cH5MeAzmyTwcWXebqmqdRL4sdJkwMzSxw5o76FqLf5vS/kFCsNQfMh1/kiltlS1px/P8M8DvwGMoe4Br01sxgAAAABJRU5ErkJggg=="
> I would like to convert this to a 28x28x3 image matrix in Octave just as the
> imread function does. Here is what works given the above string stored in
> variable imageBase64.
> raw = base64decode(imageBase64);
> fid = fopen('buffer.png', 'wb');
> fwrite(fid, raw, 'uint8');
> fclose(fid);
> I = imread('buffer.png');
> Though this outputs an I matrix of 28x28x3 dimension, for the application
> that I am building I cannot be saving to file and reading the file
> afterwards. I know the imread function only takes a file path as an input.
> Is there any way to go directly from the base64 string to the I matrix
> without writing/reading to file in Octave.

Octave's image functions are based on GraphicsMagick. GraphicsMagick
only decodes/encodes image formats to/from a file, there is no way to
decode PNG data from a memory buffer for example.

You could create a memory-backed file instead of a disk-backed file,
which should be no less efficient than what you want, or you could write
your own PNG decoding function.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]