i need to add an image as background?

2 次查看(过去 30 天)
here is my code
close all; clear all;
P = @(x,y,c,w,a) a.*exp(-((x-repmat(c(1),size(x,1),size(x,2))).^2 + (y-repmat(c(2),size(y,1),size(y,2))).^2)./w); A=[6 8 10]; W = 1; % Width (constant here, can vary as a vector if you like) C = [[18 15 5];[10 10 10]]; % Peak centers x = linspace(0,20,150); % Define ‘x’ vector
[X,Y] = meshgrid(x); pks = zeros(size(X)); % Preallocate ‘pks’ for k1 = 1:size(C,2) % Loop through ‘C’ (centers) vector pks = pks + P(X,Y,C(:,k1),W,A(k1)) ; end
A=meshz(X,Y,pks); view(2);
grid on;
colorbar
i have this code and i need to add an image as a background how can i do it?
  3 个评论
marc kahwaji
marc kahwaji 2014-8-7
find attach the image that i need to put as background

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2014-8-5
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
close all;
clear all;
P = @(x,y,c,w,a) a.*exp(-((x-repmat(c(1),size(x,1),size(x,2))).^2 + (y-repmat(c(2),size(y,1),size(y,2))).^2)./w);
A=[6 8 10];
W = 1; % Width (constant here, can vary as a vector if you like)
C = [[18 15 5];[10 10 10]]; % Peak centers
x = linspace(0,20,150); % Define ‘x’ vector
[X,Y] = meshgrid(x);
pks = zeros(size(X)); % Preallocate ‘pks’
for k1 = 1:size(C,2) % Loop through ‘C’ (centers) vector
pks = pks + P(X,Y,C(:,k1),W,A(k1)) ;
end
subplot(1,3,1);
imshow(pks);
grid on;
colorbar
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Read in background image.
backgroundImage = imread('cameraman.tif');
% Make same size as pks.
backgroundImage = double(imresize(backgroundImage, size(pks)));
% Normalize
backgroundImage = backgroundImage * max(pks(:)) / max(backgroundImage(:));
subplot(1,3,2);
imshow(backgroundImage, []);
axis on;
compositeImage = backgroundImage; % Initialize.
% Get location of circles.
circleLocations = pks > 0.001;
% Now add circles.
compositeImage(circleLocations) = pks(circleLocations);
subplot(1,3, 3);
imshow(compositeImage, []);
axis on;
  13 个评论
Image Analyst
Image Analyst 2014-8-12
numel() is the number of pixels in the image. weight says how much wieght to apply to one image. The other line just does the weighted sum. It just says how much of one image shows in comparison to the other image. Not sure how to describe weighted sum. I thought everyone knew what it was. Perhaps you can Google it.

请先登录,再进行评论。

更多回答(0 个)

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by