On this page:
fmsqrt
fmsqr
flomap-lift
flomap-normalize
fm+
fm-
fm*
fm/
fmmin
fmmax
flomap-lift2
inline-flomap-lift
inline-flomap-lift2

4.5 Pointwise Operations🔗

procedure

(fmsqrt fm)  flomap

  fm : flomap

procedure

(fmsqr fm)  flomap

  fm : flomap
Unary functions, lifted pointwise to operate on flomaps. Defined as (inline-flomap-lift flsqrt) and so on.

For example, to estimate the local gradient magnitude at each point in a flomap:
> (define-values (dx-fm dy-fm)
    (flomap-gradient (flomap-drop-components fm 1)))
> (flomap->bitmap
   (fmsqrt (fm+ (fmsqr dx-fm) (fmsqr dy-fm))))

image

procedure

(flomap-lift f)  (flomap -> flomap)

  f : (Float -> Real)
Lifts a unary floating-point function to operate pointwise on flomaps.

procedure

(flomap-normalize fm)  flomap

  fm : flomap
Returns a flomap like fm, but with values linearly rescaled to be between 0.0 and 1.0 inclusive.

Examples:
> (define gray-fm
    (build-flomap 1 100 100 (λ (k x y) (+ 0.375 (/ (+ x y) 800)))))
> (flomap->bitmap gray-fm)

image

> (flomap->bitmap (flomap-normalize gray-fm))

image

Besides increasing contrast, you could use this function to visualize oversaturated flomaps, or visualize flomaps that don’t correspond directly to displayed images, such as height maps and normal maps.

procedure

(fm+ fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)

procedure

(fm- fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)

procedure

(fm* fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)

procedure

(fm/ fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)

procedure

(fmmin fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)

procedure

(fmmax fm1 fm2)  flomap

  fm1 : (U Real flomap)
  fm2 : (U Real flomap)
Arithmetic, flmin and flmax lifted to operate pointwise on flomaps. Defined as (inline-flomap-lift2 +) and so on.

Binary operations accept the following argument combinations, in either order:
  • Two flomaps. Both flomaps must have the same number of components, or one of them must have one component. If one flomap has one component, it is (conceptually) self-appended (see flomap-append-components) as much as needed before the operation. In either case, both flomaps must have the same width and height.

  • One flomap, one Real. In this case, the real value is (conceptually) made into a uniform flomap (see make-flomap) before applying the operation.

Any other argument combination will raise a type error.

Examples:
> (define fm1 (build-flomap 1 260 240 (λ (k x y) (/ (+ x y) 500))))
> (define fm2 (fm- 1.0 fm1))
> (flomap->bitmap fm1)

image

> (flomap->bitmap fm2)

image

> (flomap->bitmap (fmmax fm1 fm2))

image

> (flomap->bitmap (fm* fm1 fm))

image

> (fm/ (make-flomap 1 10 10 0.5)
       (make-flomap 1 30 30 0.25))

fm/: expected same-size flomaps; given sizes 10×10 and 30×30

Binary pointwise operators could behave according to the Conceptual Modelthat is, expand the smaller one to the larger size by filling it with 0.0. However, operating on the components of two different-size flomaps almost always indicates a logic or design error. If it really is intended, use flomap-inset or subflomap to expand the smaller flomap manually, with more control over the expansion.

Because fm is an alpha-multiplied flomap (see Opacity (Alpha Components)), multiplying each component by a scalar less than 1.0 results in a more transparent flomap:
> (flomap->bitmap (fm* fm 0.2))

image

procedure

(flomap-lift2 f)  ((U Real flomap) (U Real flomap) -> flomap)

  f : (Float Float -> Real)
Lifts a binary floating-point function to operate pointwise on flomaps, allowing the same argument combinations as fm+ and others.

syntax

(inline-flomap-lift f)

 
  f : (Float -> Float)
A macro version of flomap-lift. The function or macro f must return a Float, not a Real as the f argument to flomap-lift can.

Using inline-flomap-lift instead of flomap-lift may ensure that f is inlined, and therefore floats remain unboxed.

This is not available in untyped Racket.

syntax

(inline-flomap-lift2 f)

 
  f : (Float Float -> Float)
A macro version of flomap-lift2. The function or macro f must return a Float, not a Real as the f argument to flomap-lift2 can.

Using inline-flomap-lift2 instead of flomap-lift2 may ensure that f is inlined, and therefore floats remain unboxed.

This is not available in untyped Racket.