Basic Goal of Simulation Matlab is to interactively simulate system and view the results on scopes and graphical displays. Perform iterative simulations in matlab without recompiling model to provide efficient and effective simulation have continuous, discrete, mixed signal system and also provides range of fixed step and variable step solvers. Simulation Matlab tool is used to implement image processing concepts in an easiest manner.
Steps Includes Matlab Simulation:
- Configure Simulation.
- Import Data.
- Run Simulation.
- Visualize Results.
- Export Runtime Information.
- Validate System Behavior.
- Test and Debug.
Run Simulation Types:
- Interactive – view live results, interact with simulation.
- Programmatic – Run multiple simulations using different model parameters.
Domains Supports of Matlab Simulation:
- Communication.
- Digital Image Processing.
- Medical Imaging.
- Remote Sensing.
Matlab Threshold Detection Methods:
- Mixture Modeling.
- Optimal Thresholding.
- P-Tile Thresholding.
- Adaptive Thresholding.
Sample code for Communication:
% CDMA Simulation for N Transmitter/Receiver Pairs
% data bit stream for each sender
D = [ 1 -1 1 -1 1 1 -1 -1 ;
-1 -1 1 1 1 -1 -1 1 ;
1 1 -1 -1 -1 1 1 -1 ;
1 1 1 1 -1 -1 -1 -1 ];
% unique code for each sender (determined using the Walsh Set)
C = [ -1 -1 -1 -1 ;
-1 1 -1 1 ;
-1 -1 1 1 ;
-1 1 1 -1 ];
% parameters
M = length(C); % length (number of bits) of code
Y = size(D);
N = Y(1); % number of unique senders / bit streams
I = Y(2); % number of bits per stream
T = []; % sum of all transmitted and encoded data on channel
RECON = []; % vector of reconstructed bits at receiver
% show data bits and codes
‘Vector of data bits to be transmitted:’, D
‘Vector of codes used for transmission:’, C
% encode bits and transmit
G = zeros(I,M);
for n = 1:N
Z = zeros(I,M);
for i = 1:I
for m = 1:M
Z(i,m) = [D(n,i)*C(n,m)];
end
end
G = G + Z;
end
% show channel traffic
for i = 1:I
T = [ T G(i,:) ];
end
‘Resulting traffic on the channel:’, T
% decode and reconstruct
for n = 1:N
TOT = zeros(1,I);
R = zeros(I,M);
for i = 1:I
for m = 1:M
R(i,m) = G(i,m) * C (n,m);
TOT(i) = TOT(i) + R (i,m);
end
end
RECON = [RECON ; TOT / M];
end
‘Reconstructed data at the receiver:’
RECON
Sample code for Medical Imaging:
Grey level thresholding:
%% initializations
videoPath = ‘Highway\RawData’; % path for input video sequence
foregroundPath = ‘Highway\ForegroundMasks’; % path for ground-truth foreground masks
shadowPath= ‘Highway\ShadowMasks’; % path for ground-truth shadow masks
outputPath = ‘Highway\results’; % path for writing detected shadows
L = 56; % window size
binSize = 10; % bin size (used to compute bin boundaries)
direction = ‘P2W’; % ‘P2W’ for pattern-to-window MTM, ‘W2P’ for window-to-pattern MTM
filesList = dir([videoPath ‘\*.jpg’]);
framesNum = size(filesList, 1) – 1; % number of frames in the sequence
bgFramesRange = [1, framesNum]; % range of frames used to build background model
% build vector of increasing values representing bin boundaries
alpha = [[0:binSize:255] 256];
if sum(alpha == 255)
alpha(end – 1) = [];
end
%% read video sequence
for curFrameNum = 1:framesNum
fileName = [videoPath ‘\’ num2str(curFrameNum, ‘%04d’) ‘.jpg’];
curFrame = imread(fileName);
sequence(:, :, curFrameNum) = curFrame(:, :, 2); % use green layer in RGB color space
end
%% compute background model
background = double(getBackground(sequence, bgFramesRange));
%% apply MTM and threshold
for curFrameNum = 1:framesNum
% read foreground mask
objectFilename = [foregroundPath ‘\’ num2str(curFrameNum, ‘%04d’) ‘ copy.jpg’];
shadowFilename = [shadowPath ‘\’ num2str(curFrameNum, ‘%04d’) ‘ copy.jpg’];
if (~exist(objectFilename, ‘file’)) | (~exist(shadowFilename, ‘file’))
continue; % if no ground-truth masks available, ignore this frame
end
objectMask = im2bw(imread(objectFilename), 0.5);
shadowMask = im2bw(imread(shadowFilename), 0.5);
foregroundMask = objectMask | shadowMask;
% apply MTM
curFrame = sequence(:, :, curFrameNum);
if strcmp(direction, ‘P2W’)
distMap = MTM_PWC(curFrame, background, foregroundMask, L, alpha);
elseif strcmp(direction, ‘W2P’)
distMap = MTM_PWC(background, curFrame, foregroundMask, L, alpha);
end
% threshold distance map
level = thresh(distMap);
foreground = im2bw(distMap, level);
end