from InSPIRE utility to read raw image allowing endian-ness in the argument line by Rex Cheung
This program reads 3D raw image. It allows endianness and shows mid-zdim coronal plane for checking

readRaw(filename,imSize,type,endian,skip)
function rawData = readRaw(filename,imSize,type,endian,skip)
%function rawData = readRaw(filename,imSize,type,skip);
% Read a raw file
% Inputs: filename, image size, image type, byte ordering, skip
% If you are using an offset to access another slice of the volume image
% be sure to multiply your skip value by the number of bytes of the type
% (i.e. float is 4 bytes).
% Inputs: filename, image size, pixel type, endian, # of values to skip.
% output: image
%   By: Catherine Wang, 
%   By: Rex Cheung, cellular modules, bug-fixes and enhancement.
%   Please cite: Implementation and validation of a three-dimensional 
%   deformable registration algorithm for targeted prostate cancer 
%   radiotherapy.Wang H, Dong L, Lii MF, Lee AL, de Crevoisier R, 
%   Mohan R, Cox JD, Kuban DA, Cheung R. IJROBP. 2005.
%   Call or email me if you have questions.

fid = fopen(filename,'rb',endian); %'b' = big-endian for X-machines, Little End in 
                                   %(little endian) for windows (http://support.microsoft.com/kb/102025)
                                   %it is the obscure fact that X programs
                                   %like to store the big part of their
                                   %number first in the memory.
%fid = fopen(filename);
if (fid < 0)
    fprintf('Filename %s does not exits\n',filename); % same as error('no such file');
    rawData = -1;
else
    status = fseek(fid,skip,'bof');
    if status == 0
        rawData = fread(fid,prod(imSize),type);
        fclose(fid);
        if (length(imSize == 3))
            slices = length(rawData)/imSize(1)/imSize(2);
            imSize(3) = slices;
        end
        rawData = reshape(rawData,imSize);
    else
        rawData = status;
    end
end

%>> t=readRaw('phantomCT.raw',[103 118 44],'short','l',0); %replace the
%             arguments based on the meta information of your image.
%>> image(t(:,:,22)) %to see mid coronal plane for this image 22 =
%                    %44/2

Contact us