To convert an image to an XYZ space (or, an m-by-n-by-3 array which RGB color space uses, according to here), you can use the imread function:
X = X = im2double(imread('images.jpg'));
R = X(:,:,1); % Only Red channel
G = X(:,:,2); % Only Green Channel
B = X(:,:,3); % Only Blue Channel
Then, you can easily continue with rgb2xyz(X);