MATLAB: Exporting pixel data from image into text

arrayimageimage analysisimage processingImage Processing ToolboxMATLAB

Hello all,
I am completely new to Matlab but I am wondering if this is possible… I have an image which is 500×500, I can currently export the pixel data into a text file and results are exported like "1, 1 = (0, 0, 0)" but I want the origin(0,0) to be in the center of the image so that -250,-250 would be the result.
Not sure if this is making sense but any help would be appreciated.

Best Answer

[nr, nc, np] = size(YourImage);
[R, C] = ndgrid((1:nr)-floor(nr/2)-1, (1:nc)-floor(nc/2)-1);
Vec = @(M) double(M(:));
data = [R(:), C(:), Vec(YourImage(:,:,1)), Vec(YourImage(:,:,2)), Vec(YourImage(:,:,3))];
fid = fopen('TheOutputFileNameGoesHere.txt', 'wt');
fprintf(fid, '%d, %d = (%d, %d, %d)\n', data.'); %transpose is important
fclose(fid)