How to place a specific pixel in a specific coordinate
조회 수: 6 (최근 30일)
이전 댓글 표시
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
DGM
2022년 6월 6일
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?
답변 (2개)
Image Analyst
2022년 6월 6일
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
Image Analyst
2022년 6월 6일
@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),".
DGM
2022년 6월 6일
편집: DGM
2022년 6월 6일
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')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!