4
\$\begingroup\$

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][[2]];
result = ImageResize[original, resultSizeX];
resultSizeY = ImageDimensions[result][[2]];

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.