% gridOverImage.m This function show and save a picture with background
% image and grid of interpolation superimposed

function [ Image ] = gridOverImage( Image, virtualMicNumber, virtualMicNumberExtended, mapsFolder, X, Y, sps32type )

imageHeight             = size( Image, 1 );
imageWidth              = size( Image, 2 );

% show background color image centered in O(0;0) with cartesian coordinates
imshow( flipud( Image ), 'XData', [ -imageWidth/2, imageWidth/2 ], 'YData', [ -imageHeight/2, +imageHeight/2 ] );
set( gcf, 'PaperUnits', 'points', 'PaperPosition', [ 0 0 imageWidth/2 imageHeight/2 ] )
set(gca, 'YDir', 'normal')
xticks([-imageWidth/2 -imageWidth/(8/3) -imageWidth/4 -imageWidth/8 0 imageWidth/8 imageWidth/4 imageWidth/(8/3) imageWidth/2])
xticklabels( { '-180', '-135', '-90', '-45', '0', '45', '90', '135', '180' } )
yticks( [ -imageHeight/2 -imageHeight/4 0 imageHeight/4 imageHeight/2 ] )
yticklabels( { '-90', '-45', '0', '45', '90' } )
axis on
hold on

scatter( -X, Y, 50, 'filled' );                                            % plot grid on background image

% add marker for each point of grid
if virtualMicNumber == 122 || ( virtualMicNumber == 32 && sps32type == 1 )
    for index = 1 : virtualMicNumberExtended
        t           = text( -X( index ), Y( index ), num2str( index ), 'HorizontalAlignment', 'right' );
        t.Color     = 'white';
        t.FontSize  = 12;
    end
else
    for index = 1 : virtualMicNumber
        t           = text( -X( index ), Y( index ), num2str( index ), 'HorizontalAlignment', 'right' );
        t.Color     = 'white';
        t.FontSize  = 12;
    end
end   
    
set( gcf, 'inverthardcopy', 'off' );                                        % export with text of choosen colour 
if ~isdir( mapsFolder )
    mkdir( mapsFolder )
end
warning( 'off', 'images:initSize:adjustingMag' )
print( [ mapsFolder 'GridOverBackground.png' ], '-dpng' );                  % save background image with grid over it
