Don't know what is wrong with my output of this code

조회 수: 1 (최근 30일)
Asuka
Asuka 2024년 6월 17일
편집: Cris LaPierre 2024년 6월 19일
function [MOVINGREG] = registerMarsImages(MOVING,FIXED)
% Convert images to grayscale if they are RGB
if size(MOVING, 3) == 3
MOVING = rgb2gray(MOVING);
end
if size(FIXED, 3) == 3
FIXED = rgb2gray(FIXED);
end
% Detect features in both images
points1 = detectSURFFeatures(MOVING, 'MetricThreshold', 1000);
points2 = detectSURFFeatures(FIXED, 'MetricThreshold', 1000);
% Extract features from both images
[features1, valid_points1] = extractFeatures(MOVING, points1);
[features2, valid_points2] = extractFeatures(FIXED, points2);
% Match features by using their descriptors
indexPairs = matchFeatures(features1, features2, 'MatchThreshold', 10, 'MaxRatio', 0.7);
% Retrieve locations of corresponding points for each image
matchedPoints1 = valid_points1(indexPairs(:, 1), :);
matchedPoints2 = valid_points2(indexPairs(:, 2), :);
% Estimate the transformation between the moving and fixed images
[tform, inlierIdx] = estimateGeometricTransform2D(matchedPoints1, matchedPoints2, 'projective', 'Confidence', 99.9, 'MaxNumTrials', 2000);
% Get the output limits for the transformation
[xLimitsMoving, yLimitsMoving] = outputLimits(tform, [1 size(MOVING, 2)], [1 size(MOVING, 1)]);
[xLimitsFixed, yLimitsFixed] = outputLimits(projective2d(eye(3)), [1 size(FIXED, 2)], [1 size(FIXED, 1)]);
% Determine the size of the panorama
xMin = min([xLimitsMoving xLimitsFixed]);
xMax = max([xLimitsMoving xLimitsFixed]);
yMin = min([yLimitsMoving yLimitsFixed]);
yMax = max([yLimitsMoving yLimitsFixed]);
width = round(xMax - xMin);
height = round(yMax - yMin);
% Create an empty panorama canvas
panorama = zeros(height, width, 'like', FIXED);
% Create reference objects for the panorama and the fixed image
panoramaView = imref2d([height width], [xMin xMax], [yMin yMax]);
fixedRef = imref2d(size(FIXED), [xLimitsFixed(1) xLimitsFixed(2)], [yLimitsFixed(1) yLimitsFixed(2)]);
% Warp the moving image into the panorama
registered = imwarp(MOVING, tform, 'OutputView', panoramaView);
% Overlay the fixed image onto the panorama
panorama = imwarp(FIXED, projective2d(eye(3)), 'OutputView', panoramaView, 'FillValues', 0);
panorama = max(panorama, registered);
% Resize the panorama to fit within 1024x1024
scaleFactor = min(1024 / width, 1024 / height);
panoramaScaled = imresize(panorama, scaleFactor);
% Create a 1024x1024 canvas
finalPanorama = zeros(1024, 1024, 'like', FIXED);
% Determine the position to center the scaled stitched image within the canvas
[scaledHeight, scaledWidth] = size(panoramaScaled);
xOffset = max(0, round((1024 - scaledWidth) / 2));
yOffset = max(0, round((1024 - scaledHeight) / 2));
% Place the scaled stitched image onto the 1024x1024 canvas
finalPanorama(yOffset + (1:scaledHeight), xOffset + (1:scaledWidth)) = panoramaScaled;
% Store the registered image
MOVINGREG.RegisteredImage = finalPanorama;
% Store the transformation object
MOVINGREG.Transformation = tform;
end
% Load the images
fixedImg = imread("sol_03333_opgs_edr_ncam_NLB_693387385EDR_F0921230NCAM00259M_.JPG");
leftImg = imread("sol_03333_opgs_edr_ncam_NLB_693387301EDR_F0921230NCAM00259M_.JPG");
% Register the two images
reg = registerMarsImages(leftImg, fixedImg)
figure; imshow(reg.RegisteredImage)
  댓글 수: 3
Asuka
Asuka 2024년 6월 18일
편집: Asuka 2024년 6월 18일
This is the final assignment from MATLAB course offered by MathWork on Coursera, and the auto grading system gave a feedback as below.
Asuka
Asuka 2024년 6월 18일
And here's the requirement for Reistration part:
Register the Images
Use the Registration Estimator app to create a function that registers the images. Then, use that function to return the registration structure.
When you're happy with your registration function, return to the course and use the online grader to check if it gives the correct result.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 6월 19일
편집: Cris LaPierre 2024년 6월 19일
Your result has stitched all 3 images together. However, the function should be returning a single image (the moving one only).
"The grader is checking that your registration function can produce a result close to the expected solution registration function. You will still need to correctly warp and stitch the images together."
Make sure you are submitting code generated by the Registration Estimator app.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by