Error in point matching in matlab code, How can I solve this?

6 Ansichten (letzte 30 Tage)
Nayana R
Nayana R am 20 Nov. 2018
Beantwortet: Brahmadev am 29 Sep. 2023
I am using matlab R2018a and my input image is a x-ray (skull) image. When i tried to match sella image with the my input image it ives an error as follows.Can you please suggest a method to solve this issue?
'matchedPoints1 and matchedPoints2 do not have enough points. The number of points in each set must be at least 3.'
im = imread('sella.bmp');
%imx = rgb2gray(im);
%boxImage = imbinarize(imx,0.5);
boxImage = rgb2gray(im);
figure;
imshow(boxImage);
title('Image of a Box');
im2= imread('055.bmp');
%imy = rgb2gray(K);
%im2 = imbinarize(imy,0.5);
% figure;
% imshow(im2);
% im2x = rgb2gray(im2);
% sceneImage = imbinarize(im2x,0.5);
sceneImage = rgb2gray(im2);
figure;
imshow(sceneImage);
title('Image of a Cluttered Scene');
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);
figure;
imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(selectStrongest(boxPoints, 100));
figure;
imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(selectStrongest(scenePoints, 300));
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ...
matchedScenePoints, 'montage');
title('Matched Points (Including Outliers)');
[tform, inlierBoxPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
newBoxPolygon = transformPointsForward(tform, boxPolygon);
figure;
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'r');
title('Detected Box');

Antworten (1)

Brahmadev
Brahmadev am 29 Sep. 2023
Hi Nayana,
The error message: 'matchedPoints1 and matchedPoints2 do not have enough points. The number of points in each set must be at least 3.' is caused due to "matchedFeatures" not being able to match enough matching points in the two images. You can see the size of "boxPairs" is "0×2 empty uint32 matrix". You can improve upon this implementation by the following ways:
  1. Use a different Point Feature type which is more suitable to your usecase. You can refer to the link below for more information on what each Point Feature does: https://www.mathworks.com/help/vision/ug/point-feature-types.html
  2. Make sure the Xray image and the Sella image are comparable in size for better Feature Matching. If not, resize and crop the images accordingly.
  3. Apply other preprocessing techniques such as Image Normalization, Histogram Equalization and Edge Detection for better Feature Matching. If both the images use a different color space, it would be useful to use color space conversion.
Also, it is recommended to use "estgeotform2d" and "estgeotform3d" instead of "estimateGeometricTransform" as they offer pre-multiply convention.
Hope this helps in resolving the issue!

Community Treasure Hunt

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

Start Hunting!

Translated by