就是在任意代码后面增加一个单引号',在同行单引号后芹蠢敬面的所有内容即被视为注释。
给你一段代码看看:
Sub Macro1()
'VBA替换日期型数据
Dim cz As String, th As String
cz = "????-*-*" '查找内容
th = 41118 '替换内容
Dim c As Range '循环档团变量,代表选中区域内的每个单元格
'注意,先选择替换的区域,注意不要选择错了地方,再执行宏,否则后果比较严重
'下面的selection即表示被选择的区域
For Each c In Selection '循环选中区域的每一个单元嫌慎格
If c.Text Like cz Then '如果单元格的显示形式和????-*-*格式一样
c.Value = th '替换
End If
Next
End Sub
TS_EXISTS=0 % if 0 regenerate the training set and do SVD on it etc etc...% establish the training set
directories = 35trainingSamplesPerDirectory = 10 % for directory-structured face database
trainingSamples = directories*trainingSamplesPerDirectoryfax = factor(trainingSamples) plotHt = prod(fax,2)/fax(length(fax))plotWd = fax(length(fax))
if (TS_EXISTS==0)
disp(['Loading the training set (',num2str(trainingSamples),' images)...'])
imageSize = 92
%exampleImage = double(imread('C:/Documents and Settings/aiw99r/My Documents/My Pictures/Brodatz Textures/D1.bmp','bmp'))
trainingSet = zeros(imageSize,imageSize,trainingSamples)
m=1
for dirNumber = 1:directories
for tspd=1:trainingSamplesPerDirectory
exampleImage = double(imread(strcat('C:\Documents and Settings\aiw99r\My Documents\Face Databases\ATandT_Cambridge\s',num2str(dirNumber),'\',num2str(tspd),'.bmp'升滑),'bmp'))
%exampleImage = double(imread(strcat('C:/Documents and Settings/aiw99r/My Documents/My Pictures/Faces/吵行腊face',num2str(im(m)),'.bmp'),'bmp'))
exIm = exampleImage(1:imageSize,1:imageSize)% crop to the desired training sample size
trainingSet(:,:,m) = exIm
m=m+1
end
end
if(1==0)
im_min = min(min(min(trainingSet)))im_max = max(max(max(trainingSet)))
figure
for m=1:trainingSamples
subplot(plotHt,plotWd,m)
imshow(trainingSet(:,:,m),[im_min im_max]),title(['带乎Original Image ',num2str(m)])
end
end
disp('Calculating mean image...')
% generate mean image
differenceImages = zeros(imageSize,imageSize,trainingSamples)
meanImage = mean(trainingSet,3)
figure,imagesc(meanImage),title('Mean Image'),colormap('gray')
disp('Calculating difference images...')
% subtract mean image to form the difference images
for m=1:trainingSamples
differenceImages(:,:,m) = trainingSet(:,:,m) - meanImage
end
%figure
%im_min = min(min(min(differenceImages)))im_max = max(max(max(differenceImages)))
%for m=1:trainingSamples
%subplot(plotHt,plotWd,m)
%imshow(differenceImages(:,:,m),[im_min im_max]),title(['Difference Image ',num2str(m)])
%end
disp('Vectorising difference images')
% form A -- which is a vector of the difference images
A = zeros(imageSize^2,trainingSamples)
for m=1:trainingSamples
A(:,m) = reshape(differenceImages(:,:,m),imageSize^2,1)
end
% form A'A and find e-vectors and e-values
%L = (A*A')
%[eVecsOfL,eVals] = eig(L) % V = full mx with columns being e-vectors, D = diagonal mx of e-values
%eVecs = zeros(imageSize^2,trainingSamples)
%eVecs = A*eVecsOfL % need to premultiply the e-vectors by A to get the e-vecs of A*A'
disp(['Extracting eigen-values and eigen-images from SVD (of ',num2str(size(A,1)*size(A,2)),'-element matrix)...'])
tic[U,S,V] = svd(A,0)toc
Eimage = zeros(imageSize,imageSize,trainingSamples)
for i = 1:trainingSamples
Eimage(:,:,i) = reshape(U(:,i),imageSize,imageSize) % the columns of U are automatically the e-vectors of A*A' (i.e., the covariance matrix)
Eval(i) = S(i,i)^2 % S is a diagonal matrix of singular values, we need to square them to get eigen-values
end
if(1==0)
figure
im_min = min(min(min(Eimage)))im_max = max(max(max(Eimage)))
for m=1:trainingSamples
subplot(plotHt,plotWd,m)
%imshow(Eimage(:,:,m),[im_min im_max]),title(['Eigen-Image ',num2str(m),' with SVD'])
imagesc(Eimage(:,:,m)),title(['Eigen-Image ',num2str(m),' with SVD']),colormap('gray')
end
end
figure,plot(Eval),title('Eigen-values')
% ---------------- END OF ASIDE ----------------------
%eVecs = U(1:exImages,1:exImages)
% perform linear combinations to get the eigen-images
%eigenImage = zeros(imageSize,imageSize,trainingSamples)
%for l=1:trainingSamples
%for k=1:trainingSamples
%eigenImage(:,:,l) = eVecs(k,l)*differenceImages(:,:,k)
%end
%end
%im_min = min(min(min(eigenImage)))im_max = max(max(max(eigenImage)))
%figure
%for l=1:trainingSamples
%subplot(plotHt,plotWd,l)
%imshow(eigenImage(:,:,l),[im_min im_max]),title(['E-Image ',num2str(l)])
% imagesc(eigenImage(:,:,l)),title(['E-Image ',num2str(l)]),colormap('gray')
% disp(['Eigenvalue ',num2str(l),' : ',num2str(Eval(l))])
%end
end
% ---------------------------------------- RECOGNITION TEST -------------------------------------------------
disp('Performing recognition...')
figure
% present a new face and attempt to recognise it
%recogniseImage = double(imread('C:/Documents and Settings/aiw99r/My Documents/My Pictures/Faces/face3.bmp','bmp'))
recogniseImage = double(imread(strcat('C:\Documents and Settings\aiw99r\My Documents\Face Databases\ATandT_Cambridge\s37\10.bmp'),'bmp'))
%recogniseImageTemp(1:121,1:160,1) = recogniseImage(1:121,2:161,1)recogniseImageTemp(1:121,161,1) = recogniseImage(1:121,1,1)recogniseImage=recogniseImageTemp% implement a 1-pixel shift to investigate how well-posed the weights are
%recogniseImage = double(imread('C:/Documents and Settings/aiw99r/My Documents/My Pictures/Faces/lady1.bmp','bmp'))
recIm = recogniseImage(1:imageSize,1:imageSize)% crop to the desired training sample size
subplot(1,3,1),imagesc(recIm),title('Image to recognise')
% transform into eigenimage space
recDiffIm = recIm-meanImage % firstly, subtract the mean from it to get the difference image
subplot(1,3,2),imagesc(recDiffIm),title('Mean Difference Image'),colormap('gray')
weight = zeros(trainingSamples,1)
for m=1:trainingSamples
weight(m) = (reshape(Eimage(:,:,m),imageSize^2,1))'*reshape(recDiffIm,imageSize^2,1) % do inner product of each eigenimage with the difference image to get a weight vector
end
% use the weights to remake the image
reconstructionImage = zeros(imageSize,imageSize)
for m=1:trainingSamples
reconstructionImage = reconstructionImage+(weight(m)*Eimage(:,:,m)) % should we incorporate in here (i.e., multiply weight(m) by eVals(m,m)????)
end
subplot(1,3,3),imagesc(reconstructionImage+meanImage),title('Eigen-image basis reconstruction'),colormap('gray')
figure,plot(weight),title('Weight vector for image to recognise')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)