im doing face recognition project.please explain the above coding in a step by step manner in how it works

4 visualizaciones (últimos 30 días)
%% illumination normalization
[x y] = ndgrid(1:size(I,1),1:size(I,2)); z = double(I); [Gx Gy] = gradient(z); mag = sqrt(Gx.^2+Gy.^2); h = fspecial('average',3); smooth = imfilter(z,h); norm_x = Gx./smooth; norm_y = Gy./smooth; niter = 10; kappa = 10; lambda = 0.25; im = double(norm_x+norm_y); figure,imshow(im),title('Smoothed image'); [rows,cols] = size(im); diff = im; var = 2;
for i = 1:niter diffl = zeros(rows+2,cols+2); diffl(2:rows+1,2:cols+1) = diff; %differences deltaN = diffl(1:rows,2:cols+1) - diff; deltaS = diffl(3:rows+2,2:cols+1) - diff; deltaE = diffl(2:rows+1,3:cols+2) - diff; deltaW = diffl(2:rows+1,1:cols) - diff;
%conduction
cN = exp(-(deltaN/kappa).^2);
cS = exp(-(deltaS/kappa).^2);
cE = exp(-(deltaE/kappa).^2);
cW = exp(-(deltaW/kappa).^2);
diff = diff+lambda*(cN.*deltaN+cS.*deltaS+cE.*deltaE+cW.*deltaW);
end
R = mat2gray(diff); bgImg = z;%Background Image fgImg = R;%Foreground Image
%Define Alpha Factor alphaFactor = 0.2;% 0 <= alphaFactor =< 1
%Size Validation bg_size = size(bgImg); fg_size = size(fgImg); sizeErr = isequal(bg_size, fg_size); if(sizeErr == 0) disp('Error: Images to be fused should be of same dimensions'); return; end
%Fuse Images fusedImg = FuseImages(bgImg, fgImg, alphaFactor); fusedImg = 25+uint8(fusedImg);
%Display Images figure; imshow(fusedImg);title('Illumination Normalized');
%% PCA feature extraction fusedImg=im2double(fusedImg); [Evalues, Evectors, x_mean]=PCA(fusedImg); figure,imshow(Evectors,[]);title('PCA');
features=entropy(x_mean)

Respuestas (1)

Hari
Hari el 18 de Feb. de 2025
Editada: Walter Roberson el 19 de Feb. de 2025
Hi,
The provide scirpt is mainly used for illumination normalization and PCA feature extraction.
Here is the some explanation for the same:
Illumination Normalization:
The code starts by computing the gradients of the image I using "gradient", which helps in identifying intensity changes. It then smooths the image using an averaging filter ("fspecial" and "imfilter") and normalizes the gradients.
[Gx, Gy] = gradient(double(I)); % Compute gradients
h = fspecial('average', 3); % Create averaging filter
smooth = imfilter(double(I), h); % Smooth the image
norm_x = Gx ./ smooth; % Normalize gradients
Anisotropic Diffusion:
This step performs anisotropic diffusion to enhance the image. It iteratively updates the image using conduction coefficients (cN, cS, cE, cW) to preserve edges.
for i = 1:niter
% Compute differences and conduction coefficients
% Update the image using the diffusion equation
end
Image Fusion:
The background and foreground images are fused using an alpha blending technique. This ensures that both images have the same dimensions before blending.
alphaFactor = 0.2;
fusedImg = FuseImages(bgImg, fgImg, alphaFactor); % Fuse images
PCA Feature Extraction:
The fused image is converted to double precision, and PCA is performed to extract features. The eigenvectors and mean are computed, and the entropy of the mean is used as a feature.
fusedImg = im2double(fusedImg);
[Evalues, Evectors, x_mean] = PCA(fusedImg); % Perform PCA
features = entropy(x_mean); % Compute entropy of the mean
Display Results:
The code displays the smoothed image, the fused image, and the PCA eigenvectors, helping visualize the effects of each processing step.
figure, imshow(im), title('Smoothed image');
figure, imshow(fusedImg), title('Illumination Normalized');
figure, imshow(Evectors, []), title('PCA');
Refer to the documentation of "gradient": https://www.mathworks.com/help/matlab/ref/gradient.html and "fspecial": https://www.mathworks.com/help/images/ref/fspecial.html for more details on these functions.
Hope this helps!

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by