function [prim, hidd] = decodeImage(fname) % DECODEIMAGE Decode embedded image. % DECODEIMAGE(IMAGEFILE) decodes embedded image file IMAGEFILE. % IMAGEFILE must be a valid file name. It will display a figure with 3 % axes. The top axis is the original image. The bottom left is the % primary image, and the bottom right is the embedded hidden image. % % [PRIMARY, HIDDEN] = DECODEIMAGE(IMAGEFILE) returns the primary image % and the hidden image data as RGB data. % % This function only works on images created by embedImage.m. % % Example: % % create embedded image % embedImage('trees.tif', 'football.jpg'); % decodeImage('trees_football.png'); % % See also EMBEDIMAGE. % % Jiro Doke % Jan 24, 2009. % Error check error(nargchk(1, 1, nargin, 'struct')); error(nargchk(0, 2, nargout, 'struct')); validateattributes(fname, {'char'}, {'row'}); if ~exist(fname, 'file') error('Utility:decodeImage:FileNotFound', ... 'File not found.'); end fInfo = imfinfo(fname); if ~isfield(fInfo, 'Comment') || ... ~ischar(fInfo.Comment) || ... ~strcmp(fInfo.Comment, 'Created by embedImage.m') error('Utility:decodeImage:InvalidFile', ... 'This only works with image files created by embedImage.m'); end imData = imread(fname); pixelVals = imData(:); pixelVals_conv = typecast(pixelVals, 'uint8'); pixelVals_conv = reshape(pixelVals_conv, 2, [])'; imData_primary = reshape(pixelVals_conv(:, 2), size(imData)); imData_hidden = reshape(pixelVals_conv(:, 1), size(imData)); if nargout == 0 figure; subplot(2,1,1);imshow(imData, 'Border', 'tight');title('Original Image'); subplot(2,2,3);imshow(imData_primary, 'Border', 'tight');title('Primary Image'); subplot(2,2,4);imshow(imData_hidden, 'Border', 'tight');title('Embedded Image'); else prim = imData_primary; if nargout > 1 hidd = imData_hidden; end end end