        
function draw_grid_on_image(corners_x,corners_y)
%Fred Cross June 2016 The Rockefeller University

plate_size=(size(corners_x,1)-1)*(size(corners_x,2)-1);

h_size=corners_y(2,1)-corners_y(1,1);
v_size=corners_x(1,2)-corners_x(1,1);

for h_index=1:size(corners_x,1)
    
    if mod(h_index-1,4)==0
        w=2;
        c=[.3 .7 1];
    else
        w=1;
        c='c';
    end
    line([corners_x(h_index,1),corners_x(h_index,end)],[corners_y(h_index,1),corners_y(h_index,end)],'Color',c,'LineWidth',w);
    if h_index>1
        text(corners_x(h_index,1)-h_size/2,corners_y(h_index,1)-h_size/2,get_rowletter(h_index-1,plate_size),'BackgroundColor','w','HorizontalAlignment','right');
        text(corners_x(h_index,end)+h_size/2,corners_y(h_index,end)-h_size/2,get_rowletter(h_index-1,plate_size),'BackgroundColor','w','HorizontalAlignment','left');
    end
end
          

for v_index=1:size(corners_x,2)
    if mod(v_index-1,4)==0
        w=2;
        c='c';
    else
        w=1;
        c='c';
    end
    line([corners_x(1,v_index),corners_x(end,v_index)],[corners_y(1,v_index),corners_y(end,v_index)],'Color',c,'LineWidth',w);
    if v_index>1
        text(corners_x(1,v_index-1)+v_size/2,corners_y(1,v_index-1)-v_size,num2str(v_index-1),'BackgroundColor','w','HorizontalAlignment','center');
        text(corners_x(end,v_index-1)+v_size/2,corners_y(end,v_index-1)+2*v_size,num2str(v_index-1),'BackgroundColor','w','HorizontalAlignment','center');
    end
       % line([corners_x(h_index-1,v_index-1),corners_x(h_index-1,v_index),corners_x(h_index,v_index),corners_x(h_index,v_index-1),corners_x(h_index-1,v_index-1)],[corners_y(h_index-1,v_index-1),corners_y(h_index-1,v_index),corners_y(h_index,v_index),corners_y(h_index,v_index-1),corners_y(h_index-1,v_index-1)],'Color','r');
    
end


   