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

조회 수: 10 (최근 30일)
Alberto Acri
Alberto Acri 2022년 10월 23일
댓글: Alberto Acri 2022년 10월 26일
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
Alberto Acri
Alberto Acri 2022년 10월 23일
편집: Alberto Acri 2022년 10월 23일
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 2022년 10월 23일
I would like to open the images obtained at the end of the "pic2points" function into a single three-dimensional image.

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

채택된 답변

Image Analyst
Image Analyst 2022년 10월 23일
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
Image Analyst
Image Analyst 2022년 10월 26일
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 2022년 10월 26일
Thank you @Image Analyst! I will make another post to see if it is possible to set a step value to my liking.

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

추가 답변 (0개)

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by