bits = reshape((dec2bin(typecast(YourImage, 'uint8'), 8) - '0').', 1, []);
orig_class = class(YourImage);
orig_size = size(YourImage);
reconstructed = reshape(typecast(uint8(bin2dec(char(reshape(bits, 8, [])+'0').')), orig_class), orig_size);
In the special case that you are willing to restrict your images to be uint8, you can simplify these steps.
Unless you are willing to restrict yourself to one fixed image size, you need to convey the original image size to the remote end somehow.
Best Answer