# Super Resolution in the Wolfram Language, Attempt 2

This is a wolfram language program I wrote for super-resolution, in this case meaning to guess at how to increase the the resolution, and so detail shown in a raster image such as a photograph.

It uses a different but related approach to its predecessor, that I created some time ago: Super Resolution in the Wolfram Language

I think that I have had more success this time.

The program upscales an image with simple interpolation, before choosing random regions from the original image to transparently replace areas of the new image if they are similar enough.

Run the program by calculating all three input blocks provided below in order, note that this seems to use up most of the available recourses on a free account for a calculation.

attempts decides how long the search takes.

Increasing required results in better candidates but each takes longer to find.

And alpha is the transparecy to use for each successful candidate.

originalSizeX = 100;
original = ImageResize[ExampleData[{"TestImage", "U2"}], originalSizeX];
resultSizeX = 300;
attempts = 20000;
required = 0.2;
alpha = 0.5;


originalSizeY = ImageDimensions[original][];
result = ImageResize[original, resultSizeX];
resultSizeY = ImageDimensions[result][];


original
result
Map[
{
candidateSize = RandomInteger@{1, originalSizeX},
candidateSourcePos = {
RandomInteger@{1, originalSizeX - candidateSize + 1},
RandomInteger[{1, originalSizeY - candidateSize + 1}]},
candidateSource = ImageTake[
original,
{candidateSourcePos[], candidateSourcePos[] + candidateSize - 1},
{candidateSourcePos[], candidateSourcePos[] + candidateSize - 1}],
candidateTargetPos = {
RandomInteger@{1, resultSizeX - candidateSize + 1},
RandomInteger@{1, resultSizeY - candidateSize + 1}},
candidateTarget = ImageTake[
result,
{candidateTargetPos[], candidateTargetPos[] + candidateSize - 1},
{candidateTargetPos[], candidateTargetPos[] + candidateSize - 1}],
dist = ImageDistance[
candidateSource, candidateTarget,
DistanceFunction -> NormalizedSquaredEuclideanDistance],
result = If[
dist < required,
ImageCompose[
result, {candidateSource, alpha},
{candidateTargetPos[] - 1, resultSizeY - candidateTargetPos[] + 1},
{Left, Top}
],
result
]
}&,
Range@attempts
];
result