Convert image pixels to XYZ-coordinates (3D plot)

11 Ansichten (letzte 30 Tage)
Alberto Acri
Alberto Acri am 23 Okt. 2022
Kommentiert: Alberto Acri am 26 Okt. 2022
Hello everyone,
I want to extend the following code:
Im = imread('./Images/Plot.png');
figure(1);
imshow(Im);
CoordinateMatrix = pic2points(Im);
scatter(CoordinateMatrix (:,1), CoordinateMatrix (:,2),'.');
figure(2);
so that:
- be able to display multiple images in the same graph (the images are in the "Images" folder that has been created; an example of an image is the one attached)
- display the graph in 3D (and not in 2D as in this case)
  2 Kommentare
Alberto Acri
Alberto Acri am 23 Okt. 2022
Bearbeitet: Alberto Acri am 23 Okt. 2022
I changed the code in the following way but it only allows me to see a transformed figure with "pic2point".
myFolder = 'C:\Users\Alberto\Downloads\pic2points\Images';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.png');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
% figure();
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
figure(1);
CoordinateMatrix = pic2points(imageArray);
scatter(CoordinateMatrix (:,1), CoordinateMatrix (:,2),'.');
figure(2);
end
Alberto Acri
Alberto Acri am 23 Okt. 2022
I would like to open the images obtained at the end of the "pic2points" function into a single three-dimensional image.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 23 Okt. 2022
Try this:
myFolder = 'C:\Users\Alberto\Downloads\pic2points\Images';
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.png');
imageFiles = dir(filePattern);
for k = 1:length(imageFiles)
baseFileName = imageFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf('Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
CoordinateMatrix = pic2points(imageArray);
scatter(CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), '.');
hold on;
end
fprintf('Done!\n');
  11 Kommentare
Image Analyst
Image Analyst am 26 Okt. 2022
Yes, just specify the color in plot3(), for example if you want blue:
plot3(CoordinateMatrix(:, 1), CoordinateMatrix(:, 2), z, 'b.');
Since it answered your question, could you please click the "Accept this answer" link?
Thanks in advance. 🙂
Alberto Acri
Alberto Acri am 26 Okt. 2022
Thank you @Image Analyst! I will make another post to see if it is possible to set a step value to my liking.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by