3

We are working with this image:

enter image description here

And we are trying a project with singular value decomposition. Here is our approach:

We start by importing the image, which has this filename on our system, but it is the image above.

image = Import["DSC_0880-7.jpg"]

Then we do this:

A = ImageData[ImageTake[image, {1, 480}, {1, 640}], "Byte"];

Then we adjusted something we found on the web to help us:

Approximate[A_, k_] := Module[
   {approximateImage},
   {U, Σ, VT} = SingularValueDecomposition[N[A], k];
   approximateImage = Graphics[
     Raster[
      U.Σ.Transpose[VT]/
       Max[U.Σ.Transpose[VT]]],
     PlotLabel -> 
      "Singular Values: " <> ToString[NumberForm[k, 3]] <> 
       "     Compression: " <>
       ToString[
        NumberForm[
         100*
          k*(1. Dimensions[A][[1]] + 
             Dimensions[A][[2]])/(Dimensions[A][[1]]*
             Dimensions[A][[2]])
          "% of Original.", 2]
        ]
     ]
   ];

Then we try this:

Show[Approximate[A, 20]]

But our image is flipped upside down.

enter image description here

Can someone help us unflip our image?

Feyre
  • 8,597
  • 2
  • 27
  • 46
David
  • 14,883
  • 4
  • 44
  • 117

1 Answers1

6

Use the DataReversed option of ImageData.

img = ExampleData[{"TestImage", "Sailboat"}];

Graphics[Raster@ImageData[img, DataReversed -> True]]

enter image description here

This discrepancy between Image and Raster is due to the differences in standard coordinate systems in image processing / matrices (top to bottom) and function plotting ($y$ axis points up):

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263