%fnameppm = './responsivity_meas/spectrometer_data/CRW_0324.ppm';
%fnametif = './responsivity_meas/tiff_data/CRW_0324.tif';

%fnum = 99;
fnum = 77;
%fnum = 65;
%fnum = 38;
fnameppm = ['./final_images/CRW_03',num2str(fnum),'.ppm'];
fnametif = ['./final_images/CRW_03',num2str(fnum),'.tif'];

[rtf, gtf, btf] = tiffread(fnametif);
imTiff = zeros(1536,2048,3);
imTiff(:,:,1) = rtf;
imTiff(:,:,2) = gtf;
imTiff(:,:,3) = btf;
figure; image(imTiff); axis equal;
input('ready?');
axis_arr = axis;
axis_arr(1) = ceil(axis_arr(1)/2)*2 - 1; % To make it odd.
axis_arr(2) = ceil(axis_arr(2)/2)*2 + 2; % To make it even-positive.
axis_arr(3) = ceil(axis_arr(3)/2)*2 - 1; % To make it odd.
axis_arr(4) = ceil(axis_arr(4)/2)*2 + 2; % To make it even-positive.



width = 2088; height = 1550;
fp = fopen(fnameppm,'rb');
im = fread(fp,4*width*height,'uint16');
im2 = reshape(im,  width*4, height)';

Line = reshape(im2', 4, width*height); % g,m,c,y
g= reshape(Line(1, :), width, height)';
m= reshape(Line(2, :), width, height)';
c= reshape(Line(3, :), width, height)';
y= reshape(Line(4, :), width, height)';

g = g(axis_arr(3):axis_arr(4), axis_arr(1):axis_arr(2));
m = m(axis_arr(3):axis_arr(4), axis_arr(1):axis_arr(2));
c = c(axis_arr(3):axis_arr(4), axis_arr(1):axis_arr(2));
y = y(axis_arr(3):axis_arr(4), axis_arr(1):axis_arr(2));

size(g)

%figure; imagesc(g); colormap gray,  axis equal
%figure; imagesc(m); colormap gray,  axis equal
%figure; imagesc(c); colormap gray,  axis equal
%figure; imagesc(y); colormap gray,  axis equal

sensorSurface = g+m+c+y;
%figure; imagesc(sensorSurface); colormap gray, axis equal

JP = imTiff(axis_arr(3):axis_arr(4), axis_arr(1):axis_arr(2),:);
figure;image(JP);
