1.8 Comparison of Dimension Reduction Methods
1.8 Comparison of Dimension Reduction Methods
1.8.2 Comparing Different Images
1.8.2 Comparing Different Images
In[]:=
im1=
;im2=
;
In[]:=
ImageDistance[im1,im2,DistanceFunction"DifferenceNormalizedEntropy"]
Out[]=
0.966133
1.8.3 Compression of Mandala
1.8.3 Compression of Mandala
In[]:=
img=
;
PCA method
In[]:=
data=ImageData[img];data//Dimensions
Out[]=
{338,338,3}
In[]:=
vector=Flatten[data];Dimensions[vector]
Out[]=
{342732}
In[]:=
dvector=Partition[vector,338];
In[]:=
decoder=DimensionReduction[dvector,85,Method"PrincipalComponentsAnalysis",TargetDevice"GPU"];
In[]:=
reduced=decoder[dvector];
In[]:=
Dimensions[reduced]
Out[]=
{1014,85}
In[]:=
reconstructed=decoder[reduced,"OriginalVectors"];
In[]:=
Dimensions[reconstructed]
Out[]=
{1014,338}
In[]:=
datarec=Partition[Partition[Flatten[reconstructed],3],338];
In[]:=
datarec//Dimensions
Out[]=
{338,338,3}
In[]:=
img75=Image[datarec]
Out[]=
In[]:=
PSNR[data100_,datacomp_,n_,m_]:=Module{d1,d2,eMSE,S,i,j},d1=Flatten[Table[Norm[data100[[i,j]]],{i,1,n},{j,1,m}]];d2=Flatten[Table[Norm[datacomp[[i,j]]],{i,1,n},{j,1,m}]];eMSE=Total[MapThread[(#1-#2)^2&,{d1,d2}]]nm;S=Max[Join[d1]];-10Log10,;
eMSE
2
S
In[]:=
PSNR[data,datarec,338,338]
Out[]=
33.0012
In[]:=
ImageDistance[img,img75,DistanceFunction"DifferenceNormalizedEntropy"]
Out[]=
0.643046
Discrete Wavelet Transform
In[]:=
dwd=DiscreteWaveletTransform[img,DaubechiesWavelet[4],1];
In[]:=
imgFunc[img_,{___,1|2|3}]:=Composition[Sharpen[#,0.5]&,ImageAdjust[#,{0,1}]&,ImageAdjust,ImageApply[Abs,#1]&][img]imgFunc[img_,wind_]:=Composition[ImageAdjust,ImageApply[Abs,#1]&][img]
In[]:=
WaveletImagePlot[dwd,Automatic,imgFunc[#1,#2]&,BaseStyleRed,ImageSize338]
Out[]=
In[]:=
img75W=dwd[{{0}},{"Rules","Inverse","Image"}][[1,2]]//RemoveBackground
Out[]=
In[]:=
PSNR[data,ImageData[img75W],338,338]
Out[]=
16.054
In[]:=
ImageDistance[img,img75W,DistanceFunction"DifferenceNormalizedEntropy"]
Out[]=
0.484494