How to place a specific pixel in a specific coordinate

2 vues (au cours des 30 derniers jours)
Ali Almakhmari
Ali Almakhmari le 6 Juin 2022
Commenté : Image Analyst le 6 Juin 2022
So I have a lot of colored pixels information (a picture that is 3072 by 4096 by 3), and also have an X, Y, and Z coordinate that corresponds to each pixel. How can I place each pixel at its respective coordinate and plot it correctly? I am attaching an example of the picture and the coordinates variables (.mat files). I hope someone can help.
  2 commentaires
DGM
DGM le 6 Juin 2022
What sort of plot do you want? Are you trying to map the image to a surface? Are you just trying to plot color points as a scatter plot?
Ali Almakhmari
Ali Almakhmari le 6 Juin 2022
A scatter plot of the pixels that is based on their x,y,z coordinates.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 6 Juin 2022
Attach the .mat files, here, not on Google drive. In the meantime, see my demo and adapt as needed.
% Demo to create a surface from a gray scale image and have the coloration of the surface taken from a different RGB image.
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
%===============================================================================
% Get the name of the demo image the user wants to use.
% Let's let the user select from a list of all the demo images that ship with the Image Processing Toolbox.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
% Demo images have extensions of TIF, PNG, and JPG. Get a list of all of them.
imageFiles = [dir(fullfile(folder,'*.TIF')); dir(fullfile(folder,'*.PNG')); dir(fullfile(folder,'*.jpg'))];
for k = 1 : length(imageFiles)
% fprintf('%d: %s\n', k, files(k).name);
[~, baseFileName, extension] = fileparts(imageFiles(k).name);
ca{k} = [baseFileName, extension];
end
% Sort the base file names alphabetically.
[ca, sortOrder] = sort(ca);
imageFiles = imageFiles(sortOrder);
button = menu('Use which gray scale demo image?', ca); % Display all image file names in a popup menu.
% Get the base filename.
baseFileName = imageFiles(button).name; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% img = imread('pears.png');
rgbImage = imread(fullFileName);
[rows, colummns, numberOfColorChannels] = size(rgbImage)
subplot(2, 2, 1);
imshow(rgbImage);
axis('on', 'image');
impixelinfo; % Let user mouse around and get RGB or gray levels.
caption = sprintf('Original Image : %s', baseFileName);
title(caption, 'FontSize', fontSize);
% Make gray scale value image.
peaksImage = flipud(peaks(100));
subplot(2, 2, 3);
imshow(peaksImage, []);
axis('on', 'image');
impixelinfo; % Let user mouse around and get RGB or gray levels.
title('Gray Scale Image of Z Values: Peaks(100)', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Apply the RGB image as a texture to the surface.
subplot(2, 2, [2,4]);
surf(peaksImage, ...
'FaceColor', 'texturemap',...
'EdgeColor', 'none',...
'Cdata', rgbImage);
view(3);
axis ij;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
if numberOfColorChannels == 1
colorbar;
end
title('Peaks Image with "Original" Image Applied as a "texturemap"', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'
  6 commentaires
Ali Almakhmari
Ali Almakhmari le 6 Juin 2022
I don't think your code does that. As I understand, your code builds a shape (peaks(100)) and then uses the surf's texture to map the picture on that surface. Which is not what I want to do. I have very specific pre-determined coordinates of where the pixels should go. And those coordinates are not linear or even connected to each other. The end result will not be a pretty picture, it will be a scatter of a bunch of pixels.
Image Analyst
Image Analyst le 6 Juin 2022
@Ali Almakhmari well obviously you replace the peaks z data with your own. I just used that z data as an example and thought you would realize that. To be explicit:
The x (whether mine in my demo or yours from your data) are the column number.
The y (whether mine in my demo or yours from your data) are the row number.
The z (whether mine in my demo or yours from your data) are the height or elevation.
rgbImage is the true color image, which you said is your "colored pixels information (a picture that is 3072 by 4096 by 3),".

Connectez-vous pour commenter.


DGM
DGM le 6 Juin 2022
Modifié(e) : DGM le 6 Juin 2022
This is a simple example of plotting color points using a scatter plot. It would take me over an hour to download your data, so I'm just going to plot the first 10000 pixels of a given image using random x,y,z data
picture = imread('peppers.png');
N = 10000;
x = rand(N,1);
y = rand(N,1);
z = rand(N,1);
% reshape image into (m*n)x3 color table
picture = im2double(reshape(picture,[],3));
scatter3(x,y,z,20,picture(1:size(x,1),:),'filled')

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by