The MNIST handwritten digit training set contains 60 thousand small images.
In[]:=
training=ResourceData["MNIST","TrainingData"]//​​MapApply@List//Table[{value,Cases[#,{i_,value}:>i]},{value,0,9}]&;
Most of them are not pretty, considering the random sample below.
In[]:=
RandomSample[#,10]&/@training[[All,2]]//Transpose//GraphicsGrid
Out[]=
With some trickery one can get better images, though. Below the top sixth of “highest probability” images per digit are averaged, and 50 closest matches for the result are found and averaged, and this result is converted to vector graphics at a higher resolution:
In[]:=
ParallelTable[​​Module[{value,images,dist},​​{value,images}=group;​​(*Learneddistributionforthisdigitvalue.*)​​dist=LearnDistribution[images,TrainingProgressReporting->None];​​(*Takemeanofhighestsixthofthetrainingsetaccordingtodistributionprobability.*)​​Mean[TakeLargestBy[images,PDF[dist,#]&,Round[Length[images]/6]]]//​​(*Adjustthicknessof2and4foraestheticpurposes.*)​​ImageAdjust//ImageAdjust[#,{0,0,value/.{2->0.8,4->1.3,_->1}}]&//​​(*Takeameanof50bestmatchesinthetrainingset.*)​​Mean[Nearest[images,#,50]]&//​​(*Thindigitsabit.*)​​ImageAdjust[#,{0,0,0.7}]&//​​(*Vectorizetheimage.*)​​ImageGraphics[ImageResize[#,Scaled[50]],{Black,White}]&],​​{group,training}]//​​GraphicsRow
Out[]=

CITE THIS NOTEBOOK

Extracting pretty handwritten digits from the MNIST training set​
by Jari Kirma​
Wolfram Community, STAFF PICKS, February 20, 2023
​https://community.wolfram.com/groups/-/m/t/2834239