-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCA.m
69 lines (58 loc) · 1.29 KB
/
PCA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
clc
clear all
%%%1,image read
file_path = '.\images4\';
img_path_list = dir(strcat(file_path,'*.bmp'));
img_num = length(img_path_list);
image = cell(1,img_num);
if img_num > 0
for j = 1:img_num
image_name = img_path_list(j).name;
image{j} = rgb2gray(imread(strcat(file_path,image_name)));
end
end
%%
Image = [];
for i = 1:222
for j = 0:359
Image((240*j+1):240*(j+1),i)=image{i}(:,j+1);
end
end
%%
C = cov(Image);
M = mean(Image);
[V,D] = eigs(C);
% V = V';
% D = D';
k = 6;
P = V(:,1:k);
%%
Image1 = zeros(86400,222);
I = ones(86400,1);
Image1 = Image-I*M;
Y = Image1*P;
D=Y*(Y'*Image);
N = floor(mapminmax(D,0,255));
N = N - Image;
Image_mean = mean(Image');
Image_mean = Image_mean';
Image2 = Image - Image_mean*ones(1,222);
image_new = cell(1,222);
for i = 1:222
for j = 0:359
image_new{i}(:,j+1) = Image2((240*j+1):240*(j+1),i);
for k=1:240
if image_new{i}(k,j+1) <90
image_new{i}(k,j+1)=0;
else
image_new{i}(k,j+1)=255;
end
end
end
end
for i = 1:222
imshow(mat2gray(image_new{i}));
end
% for i = 1:222
% D(:,i) = Y*Y'*Image(:,i);
% end