How to overlay an image on a surface plot?

조회 수: 24 (최근 30일)
Alba Peris
Alba Peris 2023년 2월 3일
댓글: xingxingcui 2023년 9월 3일
I have the following surface plot (x axis represents x coordinates, y axis represents y coordinates all in pixels), colormap represents time from 0 to 500 ms.
And I would like to overlay the plot on an image that is 198 x 251 pixels placed in the center of the plot (i.e 960, 540).
How could I do so?
Thanks.
  댓글 수: 1
xingxingcui
xingxingcui 2023년 9월 3일
Maybe you can refer to the "warp" built-in function that displays the image on the surf.

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

답변 (1개)

Image Analyst
Image Analyst 2023년 2월 3일
See attached demo for how to overlay a color image on a surface plot of a gray scale image. 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'

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by