%Resolution of monitors. Monitor 1 is on the left
p1x = 1440;
p1y = 900;
p2x = 1980;
p2y = 1080;
%Diagonal sizes in inches
diag1 = 19;
diag2 = 23.6;
D1 = sqrt(p1x^2 + p1y^2);
D2 = sqrt(p2x^2 + p2y^2);
%Scaling ratio - higher values mean the wallpaper is larger than the
%monitor, but scaled down when set as a background
aaratio = 1.59;
%Calculates the microns per pixel for each monitor
mpp1 = diag1*25400/D1;
mpp2 = diag2*25400/D2;
pixels1x = round(p1x*mpp1/mpp2*aaratio);
pixels1y = round(p1y*mpp1/mpp2*aaratio);
pixels2x = round(p2x*aaratio);
pixels2y = round(p2y*aaratio);
%The offset from the corner of the image to take the first corner of the
%first monitor
offsetx = 1;
offsety = 1500;
%The gap in pixels between the two monitors
gapx = round(150*aaratio);
gapy = round(-110*aaratio);
I = imread('inputfilename.jpg');
I1 = I(offsety:offsety + pixels1y - 1, offsetx:offsetx + pixels1x - 1,:);
I2 = I(offsety + gapy:offsety + gapy + pixels2y - 1, offsetx + pixels1x + gapx:offsetx + pixels1x + gapx + pixels2x - 1,:);
imagesc(I)
rectangle('Position', [offsetx offsety pixels1x - 1 pixels1y - 1], 'EdgeColor', 'white')
rectangle('Position', [(offsetx + pixels1x + gapx) (offsety + gapy) pixels2x - 1 pixels2y - 1], 'EdgeColor', 'white')
rectangle('Position', [1 1 offsetx offsety], 'LineStyle', '--', 'EdgeColor', 'white')
imwrite(I1, 'outputfilename.jpg', 'jpg')
imwrite(I2, 'outputfilename.jpg', 'jpg')