3
$\begingroup$

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?

$\endgroup$
1
6
$\begingroup$

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):

$\endgroup$
1
  • $\begingroup$ @Szaboics Thanks to the help. My student really appreciated the response. $\endgroup$ – David Oct 29 '16 at 2:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.