内容发布更新时间 : 2025/1/23 1:29:09星期一 下面是文章的全部内容请认真阅读。
Ica盲源分离Matlab程序
close all; clear all;
i4=imread('1.jpg'); i5=imread('2.jpg'); i6=imread('2.png'); i1=rgb2gray(i4); i2=rgb2gray(i5); i3=rgb2gray(i6);
s1=reshape(i1,[1,256*256]); s2=reshape(i2,[1,256*256]); s3=reshape(i3,[1,256*256]); s=[s1;s2;s3];sig=double(s); aorig=rand(size(sig,1)); mixedsig=aorig*sig;
ms1=reshape(mixedsig(1,:),[256,256]); ms2=reshape(mixedsig(2,:),[256,256]); ms3=reshape(mixedsig(3,:),[256,256]); figure;
subplot(331),imshow(i1),subplot(332),imshow(i2),subplot(333),imshow(i3);
subplot(334),imshow(uint8(ms1)),subplot(335),imshow(uint8(ms2)),subplot(336),imshow(uint8(ms3));
% mixedsig=zeros(size(mixedsig)); meanValue=mean(mixedsig')';
mixedsig=mixedsig-meanValue*ones(1,size(mixedsig,2)); covarianceMatrix=cov(mixedsig',1); [E,D]=eig(covarianceMatrix);
eigenvalues=flipud(sort(diag(D))); whiteningMatrix=inv(sqrt(D))*E'; dewhiteningMatrix=E*sqrt(D);
whitesig=whiteningMatrix*mixedsig; X=whitesig;
[vectorSize,numSamples]=size(X); B=zeros(vectorSize); numOFIC=vectorSize; for r=1:numOFIC
i=1;maxNumIterations=100; w=rand(vectorSize,1)-.5; w=w/norm(w);
while i<=maxNumIterations+1
w=w-B*B'*w; w=w/norm(w);
w=(X*((X'*w).^3))/numSamples-3*w; w=w/norm(w); i=i+1; end
A(:,r)=dewhiteningMatrix*w; W(r,:)=w'*whiteningMatrix; B(:,r)=w; end
icasig=W*mixedsig+(W*meanValue)*ones(1,numSamples); icasig=abs(50*icasig);
a=reshape(icasig(1,:),[256,256]); b=reshape(icasig(2,:),[256,256]); c=reshape(icasig(3,:),[256,256]);
subplot(337),imshow(uint8(a)),subplot(338),imshow(uint8(b)), subplot(339),imshow(uint8(c))