imageDir = 'path_to_your_images';
imageFiles = dir(fullfile(imageDir, '*.jpg'));
numImages = length(imageFiles);
canvas = zeros(canvasHeight, canvasWidth, 3, 'uint8');
points = cell(numImages, 1);
features = cell(numImages, 1);
tforms(numImages) = projective2d(eye(3));
I = imread(fullfile(imageDir, imageFiles(1).name));
points{1} = detectSURFFeatures(grayImage);
[features{1}, points{1}] = extractFeatures(grayImage, points{1});
I = imread(fullfile(imageDir, imageFiles(n).name));
points{n} = detectSURFFeatures(grayImage);
[features{n}, points{n}] = extractFeatures(grayImage, points{n});
indexPairs = matchFeatures(features{n}, features{n-1}, 'Unique', true);
matchedPoints1 = points{n}(indexPairs(:, 1), :);
matchedPoints2 = points{n-1}(indexPairs(:, 2), :);
tforms(n) = estimateGeometricTransform(matchedPoints1, matchedPoints2, 'projective', 'Confidence', 99.9, 'MaxNumTrials', 2000);
tforms(n).T = tforms(n).T * tforms(n-1).T;
[xlim(i,:), ylim(i,:)] = outputLimits(tforms(i), [1 size(I, 2)], [1 size(I, 1)]);
xMin = min([1; xlim(:)]);
xMax = max([canvasWidth; xlim(:)]);
yMin = min([1; ylim(:)]);
yMax = max([canvasHeight; ylim(:)]);
width = round(xMax - xMin);
height = round(yMax - yMin);
panorama = zeros([height width 3], 'like', I);
panoramaView = imref2d([height width], xLimits, yLimits);
I = imread(fullfile(imageDir, imageFiles(i).name));
warpedImage = imwarp(I, tforms(i), 'OutputView', panoramaView);
panorama = max(panorama, warpedImage);
title('Stitched Farm Image')
imwrite(panorama, 'stitched_farm_image.jpg');