i need to add an image as background?

3 views (last 30 days)
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 Comments
marc kahwaji
marc kahwaji on 7 Aug 2014
find attach the image that i need to put as background

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 5 Aug 2014
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 Comments
Image Analyst
Image Analyst on 12 Aug 2014
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.
marc kahwaji
marc kahwaji on 12 Aug 2014
okey thanks for your help !!

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!