How to place a specific pixel in a specific coordinate

4 views (last 30 days)
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.
Ali Almakhmari
Ali Almakhmari on 6 Jun 2022
A scatter plot of the pixels that is based on their x,y,z coordinates.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 6 Jun 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];
% 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);
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);
axis ij;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
if numberOfColorChannels == 1
title('Peaks Image with "Original" Image Applied as a "texturemap"', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'
Image Analyst
Image Analyst on 6 Jun 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),".

Sign in to comment.

DGM on 6 Jun 2022
Edited: DGM on 6 Jun 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));

Community Treasure Hunt

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

Start Hunting!

Translated by