Can we generate "foveated Image" in Mathematica
Asked Answered
V

3

15

"Foveated imaging is a digital image processing technique in which the image resolution, or amount of detail, varies across the image according to one or more "fixation points." A fixation point indicates the highest resolution region of the image and corresponds to the center of the eye's retina, the fovea."

enter image description here

I want to use such image to illustrate humans visual acuity, The bellow diagram shows the relative acuity of the left human eye (horizontal section) in degrees from the fovea (Wikipedia) :

enter image description here

Is there a way to create a foveated image in Mathematica using its image processing capabilities ?

Voluminous answered 12/9, 2011 at 18:15 Comment(0)
A
10

Something along the following lines may work for you. The filtering details should be adjusted to your tastes.

lena = ExampleData[{"TestImage", "Lena"}]

lena

ImageDimensions[lena]

==> {512, 512}

mask = DensityPlot[-Exp[-(x^2 + y^2)/5], {x, -4, 4}, {y, -4, 4}, 
                    Axes -> None, Frame -> None, Method -> {"ShrinkWrap" -> True}, 
                    ColorFunction -> GrayLevel, ImageSize -> 512]

mask

Show[ImageFilter[Mean[Flatten[#]] &, lena, 20, Masking -> mask], ImageSize -> 512]

enter image description here

Augustaaugustan answered 12/9, 2011 at 21:20 Comment(3)
Thank You very much, I felt this one would come from you !Voluminous
Sjoerd, I need a nice plot of the photoreceptor density in the eye in 2D such as : oculist.net/downaton502/prof/ebook/duanes/pages/v3/ch001/… Do you know about such plot of higher quality ? Or a trick to use those and make a better one ? Thanks for your attention anyway !Voluminous
@Voluminous Please note that this technique only fakes a position-dependent blur. The blur itself is constant everywhere, but is blended in with a position-dependent alpha. At least that's how I assume Masking works. So I don't think it's worthwhile trying to come up with very accurate density maps as they cannot really be used to make an accurate representation of vision acuity with this method. What you would need is a position dependent filter and I haven't found one in the mma's image processing function set. I don't think it is too difficult to program one yourself. It will be a bit slower.Augustaaugustan
C
9

Following on Sjoerd's answer, you can Fold[] a radius-dependent blur as follows.

A model for the acuity (very rough model):

Clear[acuity];
acuity[distance_, x_, y_, blindspotradius_] := 
    With[{\[Theta] = ArcTan[distance, Sqrt[x^2 + y^2]]}, 
       Clip[(Chop@Exp[-Abs[\[Theta]]/(15. Degree)] - .05)/.95, 
            {0,1}] (1. - Boole[(x + 100.)^2 + y^2 <= blindspotradius^2])]

Plot3D[acuity[250., x, y, 25], {x, -256, 256}, {y, -256, 256}, 
       PlotRange -> All, PlotPoints -> 40, ExclusionsStyle -> Automatic]

Acuity of fovea model

The example image:

size = 100;
lena = ImageResize[ExampleData[{"TestImage", "Lena"}], size];


Manipulate[
 ImageResize[
   Fold[Function[{ima, r}, 
   ImageFilter[(Mean[Flatten[#]] &), ima, 
      7*(1 - acuity[size*5, r, 0, 0]), 
      Masking -> Graphics[Disk[p/2, r], 
                    PlotRange -> {{0, size}, {0, size}}]
   ]], 
   lena, Range[10, size, 5]], 
 200], 
{{p, {size, size}}, Locator}]

Some examples:

Acuity example 1

Acuity example 2

Candleberry answered 13/9, 2011 at 16:57 Comment(7)
Thank you very much!Locator is so sweet !Voluminous
Thanks for the typo fixes, Sjoerd.Candleberry
Very clever extension! Am I mistaken to conclude that the outer areas are blurred multiple times? Wouldn't that give more blurring than specified by acuity? Perhaps the acuity function could be adapted to correct for that? BTW {"TestImage", "ResolutionChart"} makes for a nice test image too.Augustaaugustan
Indeed, there is overlapping of the blurring; it is not as pronounced if you work outward-in, i.e., replacing the Range[10,size,5] with Range[size,10,-5]. But it does need to be accounted for.Candleberry
Alternatively, Sjoerd, one could use annular masks so there is no overlap.Candleberry
So may I ask How should I adapt one or the other code to obtain Sjoerd rendering with a locator ? I am sorry I tried adjusting some parameters of JxB unsuccessfully.Voluminous
@Candleberry Indeed, just place a slightly smaller white disk on top of the black one.Augustaaugustan
C
2

WaveletMapIndexed can give a spatially-varying blur, as shown in the Mathematica documentation (WaveletMapIndexed->Examples->Applications->Image Processing). Here is an implementation of a foveatedBlur, using a compiled version of the acuity function from the other answer:

Clear[foveatedBlur];
foveatedBlur[image_, d_, cx_, cy_, blindspotradius_] := 
   Module[{sx, sy}, 
      {sy, sx} = ImageDimensions@image;
      InverseWaveletTransform@WaveletMapIndexed[ImageMultiply[#, 
          Image[acuityC[d, sx, sy, -cy + sy/2, cx - sx/2, blindspotradius]]] &, 
          StationaryWaveletTransform[image, Automatic, 6], {___,  1 | 2 | 3 | 4 | 5 | 6}]]

where the compiled acuity is

Clear[acuityC];
acuityC = Compile[{{distance, _Real}, {sx, _Integer}, {sy, _Integer}, {x0, _Real}, 
                   {y0, _Real}, {blindspotradius, _Real}}, 
            Table[With[{\[Theta] = ArcTan[distance, Sqrt[(x - x0)^2 + (y - y0)^2]]},  
                  (Exp[-Abs[\[Theta]]/(15 Degree)] - .05)/.95 
                  *(1. - Boole[(x - x0)^2 + (y - y0 + 0.25 sy)^2 <= blindspotradius^2])], 
                  {x, Floor[-sx/2], Floor[sx/2 - 1]}, {y, Floor[-sy/2], Floor[sy/2 - 1]}]];

The distance parameter sets the rate of falloff of the acuity. Focusing point {cx,cy}, and blind-spot radius are self-explanatory. Here is an example using Manipulate, looking right at Lena's right eye:

size = 256;
lena = ImageResize[ExampleData[{"TestImage", "Lena"}], size];

Manipulate[foveatedBlur[lena, d, p[[1]], p[[2]], 20], {{d, 250}, 50, 
    500}, {{p, ImageDimensions@lena/2}, Locator, Appearance -> None}]

Foveated Image Example with blind spot

See the blind spot?

Candleberry answered 12/4, 2012 at 23:16 Comment(1)
I think the basic technique is sufficiently different from ImageFilter to justify its own answer.Candleberry

© 2022 - 2024 — McMap. All rights reserved.