function im = imread_raw12(fname, Nx, Ny)
	% read a file saved as a 12 bit .raw file
	fid			= fopen(fname, 'r');
	if fid == -1
		error('unable to open file');
	end
	Nbytes		= Nx * Ny * 1.5;
	Nwords		= Nx * Ny;
	buffer_8		= fread(fid, Nbytes, 'uint8');
	fclose(fid);
	
	if numel(buffer_8) ~= Nbytes
		error('wrong size');
	end
	
	buffer_16	= zeros(1, Nwords, 'uint16');
	for word = 1 : 2 : Nwords
		msb_w1	= uint16( buffer_8((word-1)/2*3 + 1) );
		lsb_msb	= uint16( buffer_8((word-1)/2*3 + 2) );
		lsb_w2	= uint16( buffer_8((word-1)/2*3 + 3) );
		
		buffer_16(word)	= bitshift(msb_w1, +4) ...
								+ bitshift(bitand(lsb_msb,uint16(240)), -4);
		buffer_16(word+1) = lsb_w2 ...
								+ bitshift(bitand(lsb_msb,uint16(15 )), +8);
	end
	im				= reshape(buffer_16, Nx, Ny);
end