Problem with implementing eigenface method based on a sample source code - matlab

I am imitating implementation of eigenface method for face recognition in MATLAB. I am using the sample code which is briefly discussed in the following video:
https://www.youtube.com/watch?v=V-Miq_k3BJk
The sample code is attached in the following:
loaded_Image=load_img();
random_Index=round(400*rand(1,1));
random_Image=loaded_Image(:,random_Index);
rest_of_the_images=loaded_Image(:,[1:random_Index-1 random_Index+1:end]);
image_Signature=20;
white_Image=uint8(ones(1,size(rest_of_the_images,2)));
mean_value=uint8(mean(rest_of_the_images,2));
mean_Removed=bsxfun(#minus,rest_of_the_images,uint8(single(mean_value)*single(white_Image)));
L=single(mean_Removed)'*single(mean_Removed);
[V,D]=eig(L);
V=single(mean_Removed)*V;
V=V(:,end:-1:end-(image_Signature-1));
all_image_Signature=zeros(size(rest_of_the_images,2),image_Signature);
for i=1:size(rest_of_the_images,2);
all_image_Signature(i,:)=single(mean_Removed(:,i))'*V;
end
subplot(121);
imshow(reshape(random_Image,112,92));
title('Looking for this Face','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=random_Image-mean_value;
s=single(p)'*V;
z=[];
for i=1:size(rest_of_the_images,2)
z=[z,norm(all_image_Signature(i,:)-s,2)];
if(rem(i,20)==0),imshow(reshape(rest_of_the_images(:,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(rest_of_the_images(:,i),112,92));
title('Recognition Completed','FontWeight','bold','Fontsize',16,'color','red');
I do not know why we use "image_signature" variable in our code. I can not understand what value for this variable is required. can anyone help?
Best regards,
Thank you

Related

getpts MATLAB returns unrecognized function or variable 'getpts'

i'm trying to use getpts to choose points in the current figure using the mouse. However, when i run it, i'm getting the error "unrecognized function or variable 'getpts'."
Here's my code
for i=1:n
im = imread([read_path 'IMG_' num2str(i+t) '.jpg']); %Get image
figure
imshow(im)
[x,y] = getpts; %returns error
end
Any idea why that's happening?
Note: I'm using the free trial version of Matlab
I'd appreciate the help!
From the docs, getpts is in the image processing toolbox.
This isn't always obvious, you can infer it from the docs link itself:
mathworks.com/help/images/ref/getpts.html
(where a built-in would be something like mathworks.com/help/matlab/ref/sum.html)
You can also see it's nested under the image processing toolbox in the side-bar on that page.
In your trial installation of MATLAB you likely don't have this toolbox. You might know from the install process, or you could check whether the toolbox folder exists in the installation directory, e.g.

"imshowpair" matlab function alternative for octave

are there "imshowpair" matlab function alternative in octave function or method?
when try it?
error: 'imshowpair' undefined near line 15, column 15
The 'imshowpair' function belongs to the image package from Octave Forge
but has not yet been implemented.
Please read <https://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
the code:
close all
clear
clc
i=imread('1.jpg');
##BW=imbinarize(i);
BW=im2bw(i);
figure;
imshow(BW);
title('Binary image')
x=input("Enter whatever u want")
cc8=bwconncomp(BW,x);
L8=labelmatrix(cc8);
RGBLabel=label2rgb(L8,'jet','k','shuffle');
figure
imshowpair(L8,RGBLabel,'montage');
title(['lable img with ',int2str(x),'connctivity']);
imwrite(RGBLabel,'label.png');
Best Regards

Grid Generation error

I have worked out one sample code for grid analysis.
But each time I am having an error.
Here is my error and my code.
I think am using the function in matlab wrongly. Can anyone please guide me on how to run the function in matlab?
You have to give the function some input
Analyse_Grid("put something here (wf value)")

Verify this matlab code

I want to plot the fractal generated by the functions:
x(k+1)=y(k)(1+sin(0.7x(k))-1.2+sqrt(|x|))
y(k+1)=0.21-x(k)
with the initial conditions y(0)=x(0)=0, then I did the following code.
x=zeros(100);
y=zeros(100);
x(1)=0;
y(1)=0;
for k=1:100
x(k+2)=y(k+1)(1+sin(0.7x(k+1))-1.2+sqrt(abs(x+1)))
y(k+2)=0.21-x(k+1)
end
plot(x,y,'.')
So, Am I right?, or How can I fix it if I am wrong?, Well the thing is that I want to have a fractal,but I have run this out and it gave me only isolated points, the requirement is not to join them, therefore I want to know of this code has the right sintaxis and I it works well, so the thing is that if it is doing the right thing ;)
Thanks a lot for your help.
Edition
x=zeros(100);
y=zeros(100);
x(1)=0;
y(1)=0;
for k=0:100
x(k+2)=y(k+1)*(1+sin(0.7*x(k+1))-1.2*sqrt(abs(x(k+1))));
y(k+2)=0.21-x(k+1);
end
plot(x,y,'.')
Using the code you provided, I added the line print("MyPNG.png", "-dpng") and ran the code from Saturn Fiddle.
x=zeros(100);
y=zeros(100);
x(1)=0;
y(1)=0;
for k=0:100
x(k+2)=y(k+1)*(1+sin(0.7*x(k+1))-1.2*sqrt(abs(x(k+1))));
y(k+2)=0.21-x(k+1);
end
plot(x,y,'.')
print("MyPNG.png", "-dpng")

least mean square filter to reduce noise in image?

I have a reference image and output image which is having lot of noise.I created a mask for a portion in both images.I wanna design a filter which when applied to this region,can be applied to whole region.i am using least mean square method to reduce noise.But each time the mean square keeps increasing.Any idea how to sort out this problem.I am using MAT LAB to do this.Here is my code.
output=double(imread('obtained_output.jpg'));
reference=double(imread('reference_output.jpg'));
[M,N]=size(output);
upper_mask_obtained = output(1:100, 1:100);
lower_mask_obtained=output(201:300,1:100);
total_mask_obtained=[upper_mask_obtained;lower_mask_obtained];
upper_mask_reference = reference(1:100, 1:100);
lower_mask_reference=reference(201:300,1:100);
total_mask_reference=[upper_mask_reference;lower_mask_reference];
Ns=5;
[a,b]=size(total_mask_reference);
u=.000000001;
W=ones(Ns,Ns);
Y=zeros(Ns,Ns);
DD=zeros(Ns,Ns);
error=zeros(M,N);
e=zeros(Ns,Ns);
error_mask=abs(total_mask_obtained-total_mask_reference);
s= sum(sum(error_mask.^2));
mean_square_error=(s/(a*b));
while(mean_square_error>7)
for m=1+Ns:200
for n=1+Ns:100
for l=1:Ns
for k=1:Ns
Y(l,k)=total_mask_obtained(m-Ns+l-1,n-Ns+k-1);
DD(l,k)=total_mask_reference(m-Ns+l-1,n-Ns+k-1);
end
end
Z=conv2(Y,W,'same')/sum(sum(W));
e=DD(3,3)-Z(3,3);
W=(W+u*e*Y);
total_mask_obtained(m-Ns+2,n-Ns+2)=Z(3,3);
end
end
error=total_mask_reference-total_mask_obtained;
mean_square_error=sum(sum(error.^2))/(a*b);
end
figure(2);
final_output=(conv2(output,W,'same')/(sum(sum(W))));
imshow(uint8(final_output));
I think your task could be well-accomplished by using Gaussian filter. It is already built-in in Matlab. http://www.mathworks.com/help/images/ref/fspecial.html Check this for your reference. Sorry I'm new in StackOverflow. So I can't add comments yet. Sorry if it is not answer to your question.