Combine multiple 2D images from a folder diretory into a 3D environment for visualisation.

Please help with fixing and extending my code, I would like to combine images of different size from different angles or views into a 3D visualisation. The 3D visualisation has to be real not only points.
% Load images from a folder
imageFolder = 'Path';
images = imageDatastore(imageFolder);
% Detect feature points in each image
imagePoints = cell(numel(images.Files), 1);
for i = 1:numel(images.Files)
I = readimage(images, i);
grayImage = rgb2gray(I);
imagePoints{i} = detectSURFFeatures(grayImage);
end
% Extract features and match them across images
features = cell(numel(images.Files), 1);
for i = 1:numel(images.Files)
I = readimage(images, i);
grayImage = rgb2gray(I);
[features{i}, validPoints{i}] = extractFeatures(grayImage, imagePoints{i});
end
%Camera Intrinsics
focalLength = [10697 10770];
principalPoint = [2016 1512];
imageSize = [4042 3024];
intrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);
% Match features between consecutive images
indexPairs = matchFeatures(features{1}, features{2});
matchedPoints1 = validPoints{1}(indexPairs(:, 1));
matchedPoints2 = validPoints{2}(indexPairs(:, 2));
% Estimate the fundamental matrix
[F, inliers] = estimateFundamentalMatrix(matchedPoints1, matchedPoints2);
% Compute the camera poses
relativePose = relativeCameraPose(F, intrinsics, matchedPoints1(inliers), matchedPoints2(inliers));
% Reconstruct the 3D scene
Points =[];
for i = 1:length(imagePoints)
Points = vertcat(Points,imagePoints{i});
end
tracks = bundleAdjustment(Points , features, relativePose, intrinsics);
% Visualize the 3D model
pcshow(tracks);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Model Reconstruction');

3 Comments

I don't know what your code does but aren't you essentially describing computed tomography (CT)? For that you use filtered back projection. With projections from enough angles you can reconstruct the 3-D object. I'm not familiar with the functions you use so I don't know if they can do a CT-like filtered back projection.
Good day,
thank you for your response, i was not aware about this recent CT study, i will check. however, my is suppose to extract features of the image which will be SURFPoints in a single data type and then use camera calibration (which i used examples in this case for an iphone 13 pro camera at i used it to take pictures) then calculate camera poses infact view angles and then recontruct the image using bundleadjustment function to 3D points. Then i want to plot those 3D points to visualize a 3D image that i can rotate 360 degrees. From then i plan to extract target image points, the goal is to combine all 2D views images of same object and make a 3D of an object.
I am using vSLAM — Functions:
https://www.mathworks.com/help/vision/referencelist.html?type=function&s_tid=CRUX_topnav&category=visual-simultaneous-localization-and-mapping-slam
the cat function wont do what i want as it stacks image slices and i take images from different views of either z, y,x planes not only z plane

Sign in to comment.

Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Asked:

on 18 Mar 2025

Commented:

on 19 Mar 2025

Community Treasure Hunt

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

Start Hunting!