Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code of matlab run a project of Segmentation by fourier and transform inverse Z , i want to explain in handwritting ALL the code

This code of matlab run a project of Segmentation by fourier and transform inverse Z , i want to explain in handwritting ALL the code with maths equations, Just explain every step of the code i want maths expression explain , To run just download any image of net like tomografy in dark scales and rename example1.jpg or jpg
I dont want machine answers only math handwritting % List of images
imageFiles ={'EXAMPLE.jpg'};
numImages = length(imageFiles);
% Parameters
sizeIm =100;
dt =0.425;
eps =1E-7;
Nx = sizeIm;
Ny = sizeIm;
Lx =100;
Ly =100;
% Process each image
for idx =1:numImages
% Load and process the image
A = imread(imageFiles{idx});
Im = imresize(A,[sizeIm, sizeIm]);
% Convert to grayscale if not already
if size(Im,3)==3
B = rgb2gray(Im);
else
B = Im;
end
C = double(B(:));
% Grid dx=dy in mesh
x = linspace(0, Lx, Nx);
y = linspace(0, Ly, Ny);
dx = x(2)- x(1);
r =(eps)/((dx)^2);
% Array initialization
unk = Nx * Ny; % number of unknowns
M = zeros(unk, unk);
% Interior nodes
for ii =2:Nx-1
for jj =2:Ny-1
n = ii +(jj-1)* Nx; % convert point ij to mesh point
M(n, n)=-4* r +((1)/ dt); % main diagonal
M(n, n-1)= r; % left of diagonal
M(n, n+1)= r; % right of diagonal
M(n, n-Nx)= r; % left far diagonal
M(n, n+Nx)= r; % far right diagonal
end
end
% Boundary conditions
% Left border
ii =1;
for jj =2:Ny-1
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n+1)=2*r;
M(n, n+Nx)= r;
M(n, n-Nx)= r;
end
% Right border
ii = Nx;
for jj =2:Ny-1
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n-1)=2*r;
M(n, n+Nx)= r;
M(n, n-Nx)= r;
end
% Lower border
jj =1;
for ii =2:Nx-1
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n-1)= r;
M(n, n+1)= r;
M(n, n+Nx)=2*r;
end
% Upper border
jj = Ny;
for ii =2:Nx-1
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n-1)= r;
M(n, n+1)= r;
M(n, n-Nx)=2*r;
end
% Upper left corner
jj = Ny;
ii =1;
for ii =1:Nx-(Nx-1)
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n+1)=2*r;
M(n, n-Nx)=2*r;
end
% Right upper corner
jj = Ny;
ii = Nx;
for ii = Nx: Nx
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n-1)=2*r;
M(n, n-Nx)=2*r;
end
% Lower right corner
jj =1;
ii = Nx;
for ii = Nx: Nx
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n-1)=2*r;
M(n, n+Nx)=2*r;
end
% Bottom left corner
jj =1;
ii =1;
for ii =1:Nx-(Nx-1)
n = ii +(jj-1)*Nx;
M(n, n)=-4*r +(1/ dt);
M(n, n+1)=2*r;
M(n, n+Nx)=2*r;
end
% Solve the system
Uvec = M\C;
Upix = round(Uvec);
UM = reshape(Upix(:), sizeIm, []);
% Display of the processed image
figure;
imagesc(UM);
colormap(gray);
title(['Rescaling in Gray Tones - Image ', num2str(idx)]);
% Discrete Fourier Transform (DFT)
X = fft2(double(B));
% Display of the Discrete Fourier Transform
figure;
imshow(log(abs(fftshift(X))+1),[]);
colormap(jet);
colorbar;
title(['Discrete Fourier Transform (DFT)- Image ', num2str(idx)]);
% Inverse Z Transform using IFFT
Y = ifft2(X);
% Display of the Inverse Z Transform
figure;
imshow(abs(Y),[]);
title(['Inverse Z Transform - Image ', num2str(idx)]);
% Segmentation by light intensity with custom colormap
level = graythresh(B);
binaryImage = imbinarize(B, level);
% Custom Colormap (parula in this case)
colormap(parula);
% Shows the image segmented with the colormap
figure;
imagesc(binaryImage);
axis equal;
axis off;
title(['Light Intensity Segmentation (Custom Colormap)- Image ', num2str(idx)]);
colorbar;
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How is vacation and sick time accrued?

Answered: 1 week ago