Functions

Illusion

Delboeuf

class Delboeuf(illusion_strength=0, difference=0, size_min=0.25, distance=1, distance_auto=False)[source]

A class to generate the Delboeuf Illusion.

The Delboeuf illusion is an optical illusion of relative size perception, where circles of identical size appear as different because of their surrounding context. Specifically, the circle that is closely surrounded by a ring appears larger than the circle surrounded by a distant ring.

Each instance of Delboeuf contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the surrounding context, i.e. outer circles, in biasing perception of unequally sized inner circles. Specifically, the size of the outer circle relative to the inner circle (in percentage, e.g, if illusion_strength=1, it means that the outer circle will be 100% bigger, i.e., 2 times bigger than the inner circle). A negative sign means that the illusion will enhance the perception of the actual difference in circle sizes whereas a positive sign reduces this perception.

  • difference (float) – The objective size difference of the inner circles. Specifically, the size of left inner circle relative to the right (in percentage, e.g., if difference=1, it means that the left inner circle will be 100% bigger, i.e., 2 times bigger than the right). A negative sign would make the left inner circle smaller than the right inner circle.

  • size_min (float) – Size of smaller inner circle. Defaults to 0.25.

  • distance (float) – Distance between circles. Defaults to 1.

  • distance_auto (bool) – If true, distance is between edges (fixed spacing), if false (default), between centers (fixed location).

get_parameters()[source]

Returns a dictionary of parameters passed into the Delboeuf illusion.

Returns:

dict – A dictionary of all parameters passed into the Delboeuf illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of delboeuf_parameters()

  • Illusion : Name of the illusion, Delboeuf.

  • Illusion_Strength : The strength of the surrounding context in biasing illusion, by modifying illusion_strength of delboeuf_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Size_Inner_Left : Size of the inner left circle.

  • Size_Inner_Right : Size of the inner right circle.

  • Sine_Inner_Difference : Difference in areas of the left and right inner circles.

  • Size_Outer_Left : Size of the outer left rim.

  • Size_Outer_Right : Size of the outer right rim.

  • Distance : Distance between the circles, by modifying distance of delboeuf_parameters().

  • Distance_Reference : Distance between circles is computed ‘Between Edges’ or Between Centers, by modifying distance_auto of delboeuf_parameters().

  • Distance_Edges_Inner : Distance between the edges of the inner left and right circles.

  • Distance_Edges_Outer : Distance between the edges of the outer left and right rims.

  • Size_Inner_Smaller : Size of the smaller inner circle, equates to size_min of delboeuf_parameters().

  • Size_Inner_Larger : Size of the larger inner circle.

  • Size_Outer_Smaller : Size of the smaller outer rim.

  • Size_Outer_Larger : Size of the larger outer rim.

  • Position_Left : Position of the left circle.

  • Position_Right : Position of the right circle.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, outline=10, background='white', **kwargs)[source]

Create a PIL image of the Delboeuf illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • outline (float) – The width of the outline of the circles in the illusion, passed into image_circle().

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into delboeuf_parameters().

Returns:

Image – Image of the Delboeuf illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> delboeuf = pyllusion.Delboeuf(illusion_strength=3)
>>> delboeuf.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Delboeuf illusion.

Parameters:
  • window (object) – The window object initiated by psychopy.visual.Window in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into delboeuf_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> delboeuf = pyllusion.Delboeuf(difference=2, illusion_strength=3)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType='pygame', color='white')
>>> # Display illusion
>>> delboeuf.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Ebbinghaus

class Ebbinghaus(illusion_strength=0, difference=0, size_min=0.25, distance=1, distance_auto=False)[source]

A class to generate the Ebbinghaus Illusion.

The Ebbinghaus illusion is an optical illusion of relative size perception, where circles of identical size appear as different because of their surrounding context. Specifically, the central circle that is surrounded by large circles appears smaller than the central circle surrounded by small circles.

Each instance of Ebbinghaus contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the surrounding context, i.e. outer circles, in biasing perception of unequally sized inner circles. Specifically, the size of the outer circle relative to the inner circle (in percentage, e.g, if illusion_strength=1, it means that the outer circle will be 100% bigger, i.e., 2 times bigger than the inner circle). A negative sign means that the illusion will enhance the perception of the actual difference in circle sizes whereas a positive sign reduces this perception.

  • difference (float) – The objective size difference of the inner circles. Specifically, the size of left inner circle relative to the right (in percentage, e.g., if difference=1, it means that the left inner circle will be 100% bigger, i.e., 2 times bigger than the right). A negative sign would make the left inner circle smaller than the right inner circle.

  • size_min (float) – Size of smaller inner circle. Defaults to 0.25.

  • distance (float) – Distance between circles. Defaults to 1.

  • distance_auto (bool) – If true, distance is between edges (fixed spacing), if false, between centers (fixed location).

get_parameters()[source]

Returns a dictionary of parameters passed into the Ebbinghaus illusion.

Returns:

dict – Dictionary of parameters of the Ebbinghaus illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of ebbinghaus_parameters()

  • Illusion : Name of the illusion, ‘Ebbinghaus’.

  • Illusion_Strength : The strength of the surrounding context in biasing illusion, by modifying illusion_strength of ebbinghaus_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Size_Inner_Left : Size of the inner left circle.

  • Size_Inner_Right : Size of the inner right circle.

  • Sine_Inner_Difference : Difference in areas of the left and right inner circles.

  • Size_Outer_Left : Size of the surrounding circles around the left inner circle.

  • Size_Outer_Right : Size of the surrounding circles around the right inner circle.

  • Distance: Distance between the circles, by modifying distance of ebbinghaus_parameters().

  • Distance_Reference : Distance between circles is computed ‘Between Edges’ or Between Centers, by modifying distance_auto of ebbinghaus_parameters().

  • Distance_Edges_Inner : Distance between the edges of the inner left and right circles.

  • Distance_Edges_Outer : Distance between the edges of the surrounding left circles and right circles.

  • Size_Inner_Smaller : Size of the smaller inner circle, equates to size_min of ebbinghaus_parameters().

  • Size_Inner_Larger : Size of the larger inner circle.

  • Size_Outer_Smaller : Size of the smaller surrounding circles.

  • Size_Outer_Larger : Size of the larger surrounding cricles.

  • Position_Outer_x_Left : x-coordinates of the left surrounding circles.

  • Position_Outer_y_Left : y-coordinates of the left surrounding circles.

  • Position_Outer_x_Right : x-coordinates of the right surrounding circles.

  • Position_Outer_y_Right : y-coordinates of the right surrounding circles.

  • Position_Left : Position of the left inner circle.

  • Position_Right : Position of the right inner circle.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, background='white', **kwargs)[source]

Create a PIL image of the Ebbinghaus illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into ebbinghaus_parameters().

Returns:

Image – Image of the Ebbinghaus illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> ebbinghaus = pyllusion.Ebbinghaus(illusion_strength=1, difference=2)
>>> ebbinghaus.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Ebbinghaus illusion.

Parameters:
  • window (object) – The window object initiated by psychopy.visual.Window in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into ebbinghaus_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> ebbinghaus = pyllusion.Ebbinghaus(difference=2, illusion_strength=3)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType='pygame', color='white')
>>> # Display illusion
>>> ebbinghaus.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

MullerLyer

class MullerLyer(illusion_strength=0, difference=0, size_min=0.5, distance=1)[source]

A class to generate the Müller-Lyer illusion.

The Müller-Lyer illusion is an optical illusion causing the participant to perceive two segments as being of different length depending on the shape of the arrows. Specifically, the line with outward-protruding fins appears longer than the line with inward-protruding fins.

Each instance of MullerLyer contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the arrow shapes (or fins) in biasing the perception of lines of unequal lengths. Specifically, the angle of the fins in degrees, i.e., illusion_strength=20 represents a 20 degree tilt (away from vertical) of the fins. A negative sign means that the illusion will enhance the perception of the actual difference in lengths whereas a positive sign reduces this perception.

  • difference (float) – The objective length difference of the horizontal lines. Specifically, the real difference of upper horizontal line relative to the lower horizontal line. E.g., if difference=1, the upper line will be 100% longer, i.e., 2 times longer than the lower line. A negative sign would make the lower line longer than the upper line.

  • size_min (float) – Length of lower horizontal line.

  • distance (float) – Distance between the upper and lower horizontal lines.

get_parameters()[source]

Returns a dictionary of parameters passed into the Müller-Lyer illusion.

Returns:

dict – Dictionary of parameters of the Müller-Lyer illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of mullerlyer_parameters()

  • Illusion : Name of the illusion, MullerLyer.

  • Illusion_Strength : The strength of the surrounding context in biasing illusion, by modifying illusion_strength of mullerlyer_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference

  • Distance : Distance between the upper and lower horizontal lines, by modifying distance of mullerlyer_parameters()`.

  • Bottom_x1 : x-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_y1 : y-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_x2 : x-coordinate of the end point (right) of the lower horizontal line.

  • Bottom_y2 : y-coordinate of the end point (right) of the lower horizontal line.

  • Top_x1 : x-coordinate of the starting point (left) of the upper horizontal line.

  • Top_y1 : y-coordinate of the starting point (left) of the upper horizontal line.

  • Top_x2 : x-coordinate of the end point (right) of the upper horizontal line.

  • Top_y2 : y-coordinate of the end point (right) of the upper horizontal line.

  • Size_Bottom : Length of the lower horizontal line.

  • Size_Top : Length of the upper horizontal line.

  • Size_Larger : Length of the longer horizontal line.

  • Size_Smaller : Length of the shorter horizontal line, equates to size_min of mullerlyer_parameters().

  • Distractor_Length : Length of the distractor fins. Equivalent to half the length of size_min passed into mullerlyer_parameters().

  • Distractor_TopLeft_* : x- and y- coordinates of the top left fins.

  • Distractor_TopRight_* : x- and y- coordinates of the top right fins.

  • Distractor_BottomLeft_* : x- and y- coordinates of the bottom left fins.

  • Distractor_BottomRight_* : x- and y- coordinates of the bottom right fins.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, outline=20, background='white', **kwargs)[source]

Create a PIL image of the Müller-Lyer illusion.

Parameters:
  • parameters (dict) – Parameters of the Müller-Lyer illusion generated by mullerlyer_parameters().

  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • outline (float) – The width of the lines in the illusion, passed into image_line().

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into mullerlyer_parameters().

Returns:

Image – Image of the Müller-Lyer illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> mullerlyer = pyllusion.MullerLyer(difference=0.5, illusion_strength=20)
>>> mullerlyer.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Müller-Lyer illusion.

Parameters:
  • window (object) – The window object initiated by psychopy.visual.Window in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into mullerlyer_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> mullerlyer = pyllusion.MullerLyer(difference=0.5, illusion_strength=20)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pygame`, color=`white`)
>>> # Display illusion
>>> mullerlyer.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Ponzo

class Ponzo(illusion_strength=0, difference=0, size_min=0.5, distance=1)[source]

A class to generate the Ponzo illusion.

The Ponzo illusion is an optical illusion of relative size perception, where horizontal lines of identical size appear as different because of their surrounding context. Specifically, because we interpret the converging sides as mimicing railway tracks (i.e., upward-converging lines receding into the distance), the upper line appears longer than the shorter one.

Each instance of Ponzo contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the tilting vertical lines in biasing the perception of horizontal lines of unequal lengths. Specifically, the angle of the vertical lines in degrees, i.e., illusion_strength=20 represents a 20 degree tilt of the vertical lines. A negative sign means that the illusion will enhance the perception of the actual difference in lengths whereas a positive sign reduces this perception.

  • difference (float) – The objective length difference of the two horizontal lines. Specifically, the real difference of the upper horizontal line relative to the lower horizontal line. E.g., if difference=1 , the upper line will be 100% longer, i.e., 2 times longer than the lower line. A negative sign reflects the converse, where difference=-1 will result in the lower line being 100% longer than the upper line. A negative sign would make the lower line longer than the upper line.

  • size_min (float) – Length of shorter horizontal line. Defaults to 0.5.

  • distance (float) – Distance between the upper and lower horizontal lines. Defaults to 1.

get_parameters()[source]

Returns a dictionary of parameters passed into the Ponzo illusion.

Returns:

dict – Dictionary of parameters of the Ponzo illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of ponzo_parameters()

  • Illusion : Name of the illusion, Ponzo.

  • Illusion_Strength : Strength of the surrounding context in biasing illusion, by modifying illusion_strength of ponzo_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Distance : Distance between the upper and lower horizontal lines, by modifying distance of ponzo_parameters().

  • Bottom_x1 : x-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_y1 : y-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_x2 : x-coordinate of the end point (right) of the lower horizontal line.

  • Bottom_y2 : y-coordinate of the end point (right) of the lower horizontal line.

  • Top_x1 : x-coordinate of the starting point (left) of the upper horizontal line.

  • Top_y1 : y-coordinate of the starting point (left) of the upper horizontal line.

  • Top_x2 : x-coordinate of the end point (right) of the upper horizontal line.

  • Top_y2 : y-coordinate of the end point (right) of the upper horizontal line.

  • Size_Bottom : Length of the lower horizontal line.

  • Size_Top : Length of the upper horizontal line.

  • Size_Larger : Length of the longer horizontal line.

  • Size_Smaller : Length of the shorter horizontal line, equates to size_min of ponzo_parameters().

  • Side_Angle : Angle of the converging vertical lines, equates to illusion_strength of ponzo_parameters().

  • Side_Length : Length of the converging vertical lines.

  • Left_x1 : x-coordinate of the starting point (bottom) of the left converging line.

  • Left_y1 : y-coordinate of the starting point (bottom) of the left converging line.

  • Left_x2 : x-coordinate of the end point (top) of the left converging line.

  • Left_y2 : y-coordinate of the end point (top) of the left converging line.

  • Right_x1 : x-coordinate of the starting point (bottom) of the right converging line.

  • Right_y1 : y-coordinate of the starting point (bottom) of the right converging line.

  • Right_x2 : x-coordinate of the end point (top) of the right converging line.

  • Right_y2 : y-coordinate of the end point (top) of the right converging line.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, outline=20, background='white', **kwargs)[source]

Create a PIL image of the Ponzo illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • outline (float) – The width of the lines in the illusion, passed into image_line().

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into ponzo_parameters().

Returns:

Image – Image of the Ponzo illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> ponzo = pyllusion.Ponzo(illusion_strength=20)
>>> ponzo.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Ponzo illusion.

Parameters:
  • window (object) – The window object in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into ponzo_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> ponzo = pyllusion.Ponzo(illusion_strength=20)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pygame`, color="white")
>>> # Display illusion
>>> ponzo.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

VerticalHorizontal

class VerticalHorizontal(illusion_strength=0, difference=0, size_min=0.5)[source]

A class to generate the vertical-horizontal illusion.

The vertical–horizontal illusion illustrates the tendency for observers to overestimate the length of a vertical line relative to a horizontal line of the same length.

Each instance of MullerLyer contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the tilted vertical line in biasing the overestimation of its length relative to the horizontal line. Specifically, the orientation of the line in degrees, 0 being vertical and values rotating anticlockwise if the left line is rotated and clockwise if the right line is rotated. A negative sign means that the illusion will enhance the perception of the actual difference in lengths whereas a positive sign reduces this perception.

  • difference (float) – The objective length difference of the vertical and horizontal lines. Specifically, the real difference of left line relative to the right line. E.g., if difference=1, the left line will be 100% longer, i.e., 2 times longer than the right line. A negative sign would make the right line longer than the left line.

  • size_min (float) – Length of the shorter line. Defaults to 0.5.

get_parameters()[source]

Returns a dictionary of parameters passed into the vertical-horizontal illusion.

Returns:

dict – Dictionary of parameters of the vertical-horizontal illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of verticalhorizontal_parameters()

  • Illusion : Name of the illusion, VerticalHorizontal.

  • Illusion_Strength : Strength of the surrounding context in biasing illusion, by modifying illusion_strength of verticalhorizontal_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Left_x1 : x-coordinate of the starting point of the left line.

  • Left_y1 : y-coordinate of the starting point of the left line.

  • Left_x2 : x-coordinate of the end point of the left line.

  • Left_y2 : y-coordinate of the end point of the left line.

  • Left_Angle : The angle in which the left line is rotated.

  • Right_x1 : x-coordinate of the starting point of the right line.

  • Right_y1 : y-coordinate of the starting point of the right line.

  • Right_x2 : x-coordinate of the end point of the right line.

  • Right_y2 : y-coordinate of the end point of the right line.

  • Right_Angle : The angle in which the right line is rotated.

  • Size_Left : Length of the left line.

  • Size_Right : Length of the right line.

  • Size_Larger : Length of the longer line.

  • Size_Smaller : Length of the shorter line, equates to size_min of verticalhorizontal_parameters().

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, background='white', **kwargs)[source]

Create a PIL image of the vertical-horizontal illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into verticalhorizontal_parameters().

Returns:

Image – Image of the vertical-horizontal illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> verticalhorizontal = pyllusion.VerticalHorizontal(illusion_strength=20)
>>> verticalhorizontal.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the vertical-horizontal illusion.

Parameters:
  • window (object) – The window object in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into verticalhorizontal_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> verticalhorizontal = pyllusion.VerticalHorizontal(illusion_strength=90)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pygame`, color=`white`)
>>> # Display illusion
>>> verticalhorizontal.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Zollner

class Zollner(illusion_strength=0, difference=0, distractors_n=8, distractors_length=0.66)[source]

A class to generate the Zöllner illusion.

The Zöllner illusion is an optical illusion, where horizontal lines are perceived as not parallel because of their background (i.e., the slanting of the intersecting lines).

Each instance of Zollner contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the background, i.e., tilted distractor lines, in biasing the perception of unparallel horizontal lines. Specifically, the angle of the distractor lines in degrees (relative to vertical), where larger values increase susceptibility to the illusion. A positive sign means that the illusion will enhance the perception of the actual difference in slantness of the horizontal lines whereas a negative sign reduces this perception.

  • difference (float) – The objective parallel alignment of the two horizontal lines. Specifically, the angle of the two horizontal target lines in degrees, where difference=10 represents a 10 degree tilt of the lines towards each other (converging towards the right side of the pane). A negative sign flips the direction of the convergence (converging towards the left side of the pane).

  • distractors_n (int) – Number of distractor lines in the background. Defaults to 8.

  • distractors_length (float) – Length of distractor lines in the background. Defaults to 0.66.

get_parameters()[source]

Returns a dictionary of parameters passed into the Zollner illusion.

Returns:

dict – Dictionary of parameters of the Zöllner illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of zollner_parameters()

  • Illusion : Name of the illusion, Zollner.

  • Illusion_Strength : Strength of the surrounding context in biasing illusion, by modifying illusion_strength of zollner_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Top_x1 : x-coordinate of the starting point (left) of the upper horizontal line.

  • Top_y1 : y-coordinate of the starting point (left) of the upper horizontal line.

  • Top_x2 : x-coordinate of the end point (right) of the upper horizontal line.

  • Top_y2 : y-coordinate of the end point (right) of the upper horizontal line.

  • Bottom_x1 : x-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_y1 : y-coordinate of the starting point (left) of the lower horizontal line.

  • Bottom_x2 : x-coordinate of the end point (right) of the lower horizontal line.

  • Bottom_y2 : y-coordinate of the end point (right) of the lower horizontal line.

  • Distractors_n : Number of intersecting distractor lines, equates to distractors_n of zollner_parameters().

  • Distractors_Size : Length of intersecting distractor lines, equates to distractors_length of zollner_parameters().

  • Distractors_Angle : Angle of the intersecting distractor lines (relative to vertical).

  • Distractors_Top_* : x- and y- coordinates of the starting points and end points of the top distractor lines.

  • Distractors_Bottom_* : x- and y- coordinates of the starting points and end points of the bottom distractor lines.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, background='white', **kwargs)[source]

Create a PIL image of the Zöllner illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into zollner_parameters().

Returns:

Image – Image of the Zöllner illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> zollner = pyllusion.Zollner(illusion_strength=75)
>>> zollner.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Zöllner illusion.

Parameters:
  • window (object) – The window object in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into zollner_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> zollner = pyllusion.Zollner(illusion_strength=75)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pyglet`, color=`white`)
>>> # Display illusion
>>> zollner.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Poggendorff

class Poggendorff(illusion_strength=0, difference=0)[source]

A class to generate the Poggendorff illusion.

The Poggendorff illusion is an optical illusion that involves the misperception of the position of one segment of a transverse line that has been interrupted by the contour of an intervening structure.

Each instance of Poggendorff contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the line tilt in biasing the perception of an uncontinuous single line. Specifically, the orientation of the lines in degrees, 0 being vertical and larger values (in magnitude; no change with positive or negative sign) rotating clockwise. If difference and illusion_strength signs are opposite, it means that the illusion will enhance the perception of the actual difference in line misalignement, whereas if the two parameters have the same signs, the illusion acts to reduce this perception.

  • difference (float) – The objective magnitude of the lines discontinuity. Specifically, the amount of displacement of the right line relative to the left line. A positive sign represents the right line displaced higher up, and a negative sign represents it displaced lower down.

get_parameters()[source]

Returns a dictionary of parameters passed into the Poggendorff illusion.

Returns:

dict – Dictionary of parameters of the Poggendorff illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of poggendorff_parameters()

  • Illusion : Name of the illusion, Poggendorff.

  • Illusion_Strength : Strength of the surrounding context in biasing illusion, by modifying illusion_strength of poggendorff_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Left_x1 : x-coordinate of the starting point (from centre) of the left line segment.

  • Left_y1 : y-coordinate of the starting point (from centre) of the left line segment.

  • Left_x2 : x-coordinate of the end point (leftwards) of the left line segment.

  • Left_y2 : y-coordinate of the end point (leftwards) of the left line segment.

  • Right_x1 : x-coordinate of the starting point (from centre) of the right line segment.

  • Right_y1 : y-coordinate of the starting point (from centre) of the right line segment.

  • Right_x2 : x-coordinate of the end point (rightwards) of the right line segment.

  • Right_y2 : y-coordinate of the end point (rightwards) of the right line segment.

  • Angle : Angle displacement of the transverse line from horizontal.

  • Rectangle_Height : Height of rectangle.

  • Rectangle_Width : Width of rectangle.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, background='white', **kwargs)[source]

Create a PIL image of the Poggendorff illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • background (str) – Color of the background.

  • **kwargs – Additional arguments passed into poggendorff_parameters().

Returns:

Image – Image of the Poggendorff illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> poggendorff = pyllusion.Poggendorff(illusion_strength=-55)
>>> poggendorff.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Poggendorff illusion.

Parameters:
  • window (object) – The window object in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into poggendorff_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> poggendorff = pyllusion.Poggendorff(illusion_strength=-50)
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pygame`, color="white")
>>> # Display illusion
>>> poggendorff.to_psychopy(window=window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Contrast

class Contrast(illusion_strength=0, difference=0)[source]

A class to generate the Simultaneous Contrast illusion.

Simultaneous contrast, identified by Michel Eugène Chevreul, refers to the manner in which the colors of two different objects affect each other. Specifically, when comparing two targets with the same shade of grey, the one that is embedded against a darker background appears lighter than the other target embedded against a lighter background.

Each instance of Contrast contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the background, i.e., contrasting colours, in biasing the perception of inner rectangles of different grey shades. Specifically, the difference in background colours, where large values create greater contrast in the two grey backgrounds. A positive sign means that the illusion will enhance the perception of the actual difference in brightness contrast of the two inner rectangles, whereas a negative sign reduces this perception.

  • difference (float) – The objective difference of the grey shades of the two inner rectangles. Large positive signs reflect a darker lower rectangle relative to the upper rectangle, and negative signs reflect a darker upper rectangle relative to the lower rectangle.

get_parameters()[source]

Returns a dictionary of parameters passed into the Simultaneous Contrast illusion.

Returns:

dict – Dictionary of parameters of the Simultaneous Contrast illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of contrast_parameters().

  • Illusion : Name of the illusion, Contrast.

  • Illusion_Strength : The strength of the surrounding context in biasing illusion, by modifying illusion_strength of contrast_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Rectangle_Top : Luminance of the top inner rectangle.

  • Rectangle_Bottom : Luminance of the bottom inner rectangle.

  • Background_Top : Luminance of the top half of the background.

  • Background_Bottom : Luminance of the bottom half of the background.

  • Rectangle_Top_RGB : RGB value of the top inner rectangle.

  • Rectangle_Bottom_RGB : RGB value of the bottom inner rectangle.

  • Background_Top_RGB : RGB value of the top half of the background.

  • Background_Bottom_RGB : RGB value of the bottom half of the background.

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, **kwargs)[source]

Create a PIL image of the Simultaneous Contrast illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • **kwargs – Additional arguments passed into contrast_parameters().

Returns:

Image – Image of the Simultaneous Contrast illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> contrast = pyllusion.Contrast(illusion_strength=-50, difference=0)
>>> contrast.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the Simultaneous Contrast illusion.

Parameters:
  • window (object) – The window object in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into contrast_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> contrast = pyllusion.Contrast(difference=0, illusion_strength=-50)
>>> parameters = contrast.get_parameters()
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType='pygame',
                           color=parameters["Background_Top_RGB"],
                           colorSpace='rgb255')
>>> # Display illusion
>>> contrast.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

White

class White(illusion_strength=0, difference=0, strips_n=9)[source]

A class to generate the White’s illusion.

White’s illusion is a brightness illusion in which rectangles of the same grey color are perceived of different luminance depending on their background. Specifically, rectangles embedded against a darker background appears lighter than the rectangles embedded against a lighter background.

Each instance of White contains attributes corresponding to the parameters of the illusion.

Parameters:
  • illusion_strength (float) – The strength of the background, i.e., contrasting colours, in biasing the perception of inner rectangles of different grey shades. Specifically, the difference in background colours, where large values create greater contrast in the two grey backgrounds. A positive sign means that the illusion will enhance the perception of the actual difference in brightness contrast of the two inner rectangles, whereas a negative sign reduces this perception.

  • difference (float) – The objective difference of the grey shades of the two inner rectangles. Specifically, the brightness of the left grey rectangles relative to the right grey rectangles. Large positive signs correspond to brighter left rectangles and negative signs correspond to brighter right rectangles.

  • strips_n (int) – Number of rows of contrasting segments. Defaults to 9.

get_parameters()[source]

Returns a dictionary of parameters passed into the White`s illusion.

Returns:

dict – Dictionary of parameters of the White`s illusion, including:

  • Difference : Objective difference in the target features, by modifying difference of white_parameters()

  • Illusion : Name of the illusion, White’s.

  • Illusion_Strength : Strength of the surrounding context in biasing illusion, by modifying illusion_strength of white_parameters().

  • Illusion_Type : Congruent if the illusion enhances the perception of the objective difference in the illusion, and Incongruent if it reduces the perceived difference.

  • Target1 : Luminance of the left grey rectangles.

  • Target2 : Luminance of the right grey rectangle.

  • Background1 : Luminance of the background that Target1 is embedded in.

  • Background2 : Luminance of the background that Target2 is embedded in.

  • Target1_RGB : RGB value of the left grey rectangles.

  • Target2_RGB : RGB value of the right grey rectangle.

  • Background1_RGB : RGB value of the background that Target1 is embedded in.

  • Background2_RGB : RGB value of the background that Target2 is embedded in.

  • Target1_y : y-coordinates of the left grey rectangles.

  • Target2_y : y-coordinates of the right grey rectangles.

  • Target_Height : Height of each strip of rectangular segment.

  • Target_n : Number of horizontal rectangular segments, equates to strips_n in white_parameters().

to_dict()[source]

Alias for get_parameters().

to_image(width=800, height=600, **kwargs)[source]

Create a PIL image of the White`s illusion.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • **kwargs – Additional arguments passed into white_parameters().

Returns:

Image – Image of the white illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> white = pyllusion.White(difference=0, illusion_strength=100)
>>> white.to_image()
to_psychopy(window, **kwargs)[source]

Create a PsychoPy stimulus of the White`s illusion.

Parameters:
  • window (object) – The window object initiated by psychopy.visual.Window in which the stimulus will be rendered.

  • **kwargs – Additional arguments passed into white_parameters().

Returns:

In-place modification of the PsychoPy window (No explicit return).

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Create parameters
>>> white = pyllusion.White(difference=0, illusion_strength=100)
>>> parameters = white.get_parameters()
>>> # Initiate Window
>>> window = visual.Window(size=[800, 600], winType=`pygame`,
                           color=parameters["Background1_RGB"], colorSpace=`rgb255`)
>>> # Display illusion
>>> white.to_psychopy(window)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Autostereogram

class Autostereogram(stimulus='Hello', pattern=None, n_repetitions=14, depth=1, invert=False, **kwargs)[source]

A class to generate Autostereograms based on a given depth map.

Autostereograms are images made of a pattern that is horizontally repeated (with slight variations) which, when watched with the appropriate focus, will generate an illusion of depth.

draw(guide=True)[source]

Create a PIL image of Autostereograms.

Parameters:

guide (bool) – Defaults to ‘True’ to activate two red dots as guidance, and ‘False’ to disable the guide.

Returns:

Image – Image of the Autostereograms illusion, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> autostereograms = pyllusion.Autostereogram(stimulus="3D", width=1000, height=500, font="arialbd.ttf")
>>> autostereograms.draw(guide=True)

Pareidolia

class Pareidolia(pattern=None, n=[10, 1000], sd=[20, 2], weight=[2, 1], alpha=80, blur=30)[source]

A class to create (pseudo)noise images.

Pareidolia is the tendency to incorrectly perceive of a stimulus as an object pattern or meaning known to the observer. To create stimuli for the observation of such phenomenon, this function creates pure-noise images using bivariate Gaussian blobs with different standard deviations (SD).

draw(negative=False)[source]

Create a PIL image of a Pareidolia image.

Parameters:

negative (bool) – Activate ‘True’ to invert pixel values (negative-positive inverting) of an image. Defaults to ‘False’. Passed to PIL.ImageOps.invert.

Returns:

Image – Image of the Pareidolia image, defaults to 800 x 600 pixels. Can be resized (resize(), See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize) and saved in different file formats (save() See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html).

Examples

>>> import pyllusion
>>>
>>> pareidolia = pyllusion.Pareidolia((480, 480), n=[20, 300, 4000], sd=[4, 2, 1], weight=[3, 2, 1], alpha=80, blur=0.5)
>>> pareidolia.draw()  
<PIL.Image.Image ...>

Image

Pyllusion submodule.

image_blob(x=450, y=100, width=800, height=600, sd=30)[source]

Returns a PIL image of a blob.

Parameters:
  • x (int) – x-coordinate of the center of the blob. Unit in pixel.

  • y (int) – y-coordinate of the center of the blob. Unit in pixel.

  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • sd (int) – The standard deviation of the gaussian blob. Unit in pixel.

Returns:

  • Image – Image of blob.

  • >>> import pyllusion

  • >>>

  • >>> pyllusion.image_blob()

image_blobs(width=500, height=500, n=100, sd=8, weight=1)[source]

Returns a PIL image with blobs of the same standard deviations (SD).

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • n (int) – Number of gaussian blobs drawn in the returned image.

  • sd (int) – The standard deviation of the gaussian blob. Unit in pixel.

  • weight (int) – A multiplication weight in case there are several layers of SDs.

Returns:

Image – Image of blob(s).

Examples

>>> import pyllusion
>>>
>>> pyllusion.image_blobs(n=100)
>>> pyllusion.image_blobs(n=[5, 300, 1000], sd=[50, 10, 5], weight=[1, 1.5, 2])
image_circle(width=800, height=600, x=0, y=0, size=1, color='black', outline=0, color_outline='black', alpha=1, blur=0, antialias=True, image=None, background='white')[source]

Creates a PIL image of a circle.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • x (Union[list, np.array, pd.Series]) – x-coordinates of the circle from -1 to 1.

  • y (Union[list, np.array, pd.Series]) – y-coordinates of the circle from -1 to 1.

  • size (int) – The diameter of the circle drawn.

  • color (str) – Color of the circle returned.

  • outline (float) – The width of the outline of the circle.

  • color_outline (str) – Outline of the circle outline returned.

  • alpha (int) – Transparency of the circle drawn, 0 (transparent) to 1 (opaque).

  • blur (int) – Degree of blur filter for the image returned.

  • antialias (bool) – If true, resize the image using a high-quality downsampling filter.

  • image (Image) – If None, an image will be created.

  • background (str) – Color of the background.

Returns:

Image – Image of circle.

Examples

>>> import pyllusion
>>>
>>> image = pyllusion.image_circle()
>>> image = pyllusion.image_circle(image=image, color="red", x=0.5, size=0.5)
>>> image = pyllusion.image_circle(image=image, color="blue", x=-0.3, size=0.5, blur=0.05)
>>> image = pyllusion.image_circle(image=image, color="yellow", y=0.5, alpha=0.5)
>>> image = pyllusion.image_circle(image=image, color="white", size=0.3, y=-0.5, outline=1)
>>> image
image_circles(width=500, height=500, n=100, x=None, y=None, size_min=0.05, size_max=0.2, size=None, color=None, alpha=1, blur=0, antialias=True, image=None, background='white')[source]

Creates a PIL image of circles.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • n (int) – Number of circles drawn in the returned image.

  • x (Union[list, np.array, pd.Series]) – x-coordinates of all circles from -1 to 1.

  • y (Union[list, np.array, pd.Series]) – y-coordinates of all circles from -1 to 1.

  • size_min, size_max (int) – The minimum and maximum diameter of the circles drawn. Used only if size is None. If used, circles of random diameters from size_min to size_max are displayed.

  • size (int) – The diameters of the circles drawn. Defaults to None.

  • color (str) – Color of the circles returned.

  • alpha (int) – Transparency of the circles drawn, 0 (transparent) to 1 (opaque).

  • blur (int) – Degree of blur filter for the image returned.

  • antialias (bool) – If true, resize the image using a high-quality downsampling filter.

  • image (Image) – If None, an image will be created.

  • background (str) – Color of the background.

Returns:

Image – Image of circle(s).

Examples

>>> import pyllusion
>>>
>>> image = pyllusion.image_circles()
>>> image = pyllusion.image_circles(color="bw", blur=0.01)
>>> image = pyllusion.image_circles(n=250, size_min=0.1, size_max=0.6, alpha=0.5)
>>> image
image_line(width=800, height=600, x=0, y=0, x1=None, y1=None, x2=None, y2=None, length=1, rotate=0, size=1, color='black', background='white', blur=0, antialias=True, image=None, adjust_width=False, adjust_height=False, **kwargs)[source]

Creates a PIL image of a line.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • x (int) – x-coordinates of the center of the line, from -1 to 1.

  • y (int) – y-coordinates of the center of the line, from -1 to 1.

  • x1, x2 (int) – x-coordinates of the ends of the line, from -1 to 1. If not None, x is set to None.

  • y1, y2 (int) – y-coordinates of the ends of the line, from -1 to 1. If not None, y is set to None.

  • length (int) – Length of the line returned.

  • rotate (float) – The orientation of the line in degrees, 0 being vertical and positive values rotating clockwise. Beyond 360 and below zero values wrap appropriately.

  • size (int) – Width of the line returned.

  • color (str) – Color of the line returned.

  • background (str) – Background color.

  • blur (int) – The degree of blur filter for the image returned.

  • antialias (bool) – If true, resize the image using a high-quality downsampling filter.

  • image (Image) – If None, an image will be created.

  • adjust_width (bool) – If set to True and image is not None, the x-coordinates of the line can be adjusted to the height and width of the input image.

  • adjust_height (bool) – If set to True and image is not None, the y-coordinates of the line can be adjusted to the height and width of the input image.

Returns:

Image – Image of a line.

Examples

>>> import pyllusion
>>>
>>> image = pyllusion.image_line(x=0, y=0, length=1)
>>> image = pyllusion.image_line(image=image, x1=0, y1=0, length=0.5, rotate=90, color="green")
>>> image = pyllusion.image_line(image=image, x1=0, y1=0, length=0.5, rotate=45)
>>> image = pyllusion.image_line(image=image, x=0, y=0, length=1, rotate=135, color="blue")
>>> image = pyllusion.image_line(image=image, length=1, rotate=20, color="red")
>>> image = pyllusion.image_line(image=image, x1=0, y1=0, length=0.5, rotate=-90, size=3)
>>> image = pyllusion.image_line(image=image, x1=-1, y1=-1, length=1, rotate=45, size=5, blur=0.005)
>>> image
image_mosaic(image_list, ncols='auto', nrows='auto')[source]

Collate images together in a mosaic.

Parameters:
  • image_list (list) – A list of PIL images.

  • ncols, nrows (int) – How many rows and columns.

Returns:

Image – A PIL image.

Examples

>>> import pyllusion
>>>
>>> img1 = pyllusion.delboeuf_image()
>>> img2 = pyllusion.ponzo_image()
>>> img3 = pyllusion.rodframe_image()
>>> img4 = pyllusion.mullerlyer_image()
>>> img5 = pyllusion.ebbinghaus_image()
>>> pyllusion.image_mosaic([img1, img2, img3, img4, img5], ncols=2)
image_noise(width=500, height=500, red=<built-in method uniform of numpy.random.mtrand.RandomState object>, green=<built-in method uniform of numpy.random.mtrand.RandomState object>, blue=<built-in method uniform of numpy.random.mtrand.RandomState object>, blackwhite=False, blur=0, **kwargs)[source]

Creates a PIL RGB image of specific dimensions made of random dots.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • red, green, blue (callable) – Function to generate random color.

  • blackwhite (bool) – If True, image is converted to black and white.

  • blur (int) – The degree of blur filter for the image returned.

  • **kwargs – Additional arguments passed into _rgb().

Returns:

Image – Image of noises made of random dots.

Examples

>>> import pyllusion
>>>
>>> pyllusion.image_noise()
>>> pyllusion.image_noise(blackwhite=True)
>>> pyllusion.image_noise(blur=0.005)
image_rectangle(width=800, height=600, x=0, y=0, size_width=1, size_height=1, rotate=0, color='black', outline=0, color_outline='black', background='white', alpha=1, blur=0, antialias=True, adjust_width=False, adjust_height=False, image=None)[source]

Creates a PIL image of a rectangle.

Parameters:
  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • x (Union[list, np.array, pd.Series]) – x-coordinates of the rectangle from -1 to 1.

  • y (Union[list, np.array, pd.Series]) – y-coordinates of the rectangle from -1 to 1.

  • size_width (int) – Width of the rectangle drawn.

  • size_height (int) – Height of the rectangle drawn.

  • rotate (int) – The orientation of the rectangle in degrees, 0 being vertical and positive values rotating clockwise.

  • color (str) – Color of the line returned.

  • outline (int) – Width of the outline.

  • color_outline (str) – Color of the outline.

  • background (str) – Color of the background.

  • alpha (int) – Transparency of the rectangle drawn, 0 (transparent) to 1 (opaque).

  • blur (int) – Degree of blur filter for the image returned.

  • antialias (bool) – If true, resize the image using a high-quality downsampling filter.

  • adjust_width (bool) – If set to True, the size_width can be adjusted to the height and width of the image.

  • adjust_height (bool) – If set to True, the size_height can be adjusted to the height and width of the image.

  • image (Image) – If None, an image will be created.

Returns:

Image – Image of a rectangle.

Examples

>>> import pyllusion
>>>
>>> image = pyllusion.image_rectangle(x=0, y=0, color=(0,0,0,0), outline=3, rotate=1)
>>> image = pyllusion.image_rectangle(image=image, x=0.5, size_width=0.5, rotate=45, color="red")
>>> image = pyllusion.image_rectangle(image=image, y=0.25, size_height=0.2,  color="yellow", alpha=0.5)
>>> image = pyllusion.image_rectangle(image=image, size_width=0.5, size_height=0.5, blur=0.01, color="green", adjust_width=True)
>>> image
image_text(text='Hello', width=500, height=500, x=0, y=0, size='auto', color='black', background='white', font='arial.ttf', blur=0, image=None)[source]

Creates a PIL image of text.

Parameters:
  • text (str) – The text displayed in the image returned.

  • width (int) – Width of the returned image.

  • height (int) – Height of the returned image.

  • x (int) – x-coordinates of the center of the text display, from -1 to 1.

  • y (int) – y-coordinates of the center of the text display, from -1 to 1.

  • size (int) – Requested size, in points, for the text. If “auto”, the maximum size that fits the image will be chosen.

  • color (str) – Text color.

  • background (str) – Background color.

  • font (str) – The name of the font to be used. Note that the font is what controls features like bold / italic. For instance, ‘arialbd.ttf’, ‘ariblk.ttf’ or ‘ariali.ttf’ can be used for bold, black and italic, respectively.

  • blur (int) – The degree of blur filter for the image returned.

  • image (Image) – If None, an image will be created.

Returns:

Image – Image of a text.

Examples

>>> import pyllusion
>>>
>>> image = pyllusion.image_text(text="Hello", size=40)
>>> image = pyllusion.image_text(image=image, size=30, y=0.5, text="I'm Red", color="red")
>>> image = pyllusion.image_text(image=image, size=20, x=0.5, text="Bold and blurred", font="arialbd.ttf", blur=0.005)
>>> image
>>> pyllusion.image_text(text="3D", width=1600, height=900, font="arial.ttf", blur=0.01)
>>> image
rescale(x, to=[0, 1], scale=None)[source]

Rescale data.

Rescale a numeric variable to a new range.

Parameters:
  • x (Union[list, np.array, pd.Series]) – Raw data.

  • to (list) – New range of values of x after rescaling.

  • scale (list) – A list or tuple of two values specifying the actual range of the data. If None, the minimum and the maximum of the provided data will be used.

Returns:

list – The rescaled values.

Examples

>>> import pyllusion
>>>
>>> pyllusion.rescale([3, 1, 2, 4, 6], to=[0, 1]) 
[0.4, 0.0, 0.2, 0.6000000000000001, 1.0]

PsychoPy

Pyllusion submodule.

psychopy_circle(window, x=0, y=0, size=1, color='black', outline=1, outline_color='black', alpha=0, blur=0, **kwargs)[source]

Creates a PsychoPy stimulus of a circle.

The *_circle functions are meant to facilitate the creation of primitive shapes, in this case, circle(s), that can be assembled into illusory stimuli.

This function is intended to create circles similar to image_circle() within PsychoPy. It is essentially a wrapper around PsychoPy psychopy.visual.Circle(). The difference lies within the names of the arguments and the values that they take (e.g., we use a consistent x-y plane [-1, 1; -1, 1] for the screen “space” with 0 as the center, instead of pixels starting from the corner). The purpose of this wrapper is to have consistent behaviour for functions that are based on the different backends (e.g., PIL, PsychoPy). See the PsychoPy documentation for more information (https://www.psychopy.org/api/visual/circle.html).

Parameters:
  • window (object) – A PsychoPy window for displaying one or more stimuli.

  • x (float) – x-coordinates of the center of the circle, from -1 to 1.

  • y (float) – y-coordinates of the center of the circle, from -1 to 1.

  • color (Union[list, str]) – The fill color of the circle as single string value or [r, g, b] list, in which colorSpace=’rgb255’ argument has to be added.

  • outline (float) – The width of the outline of the circle.

  • outline_color (Union[list, str]) – The outline color of the circle as single string value or [r, g, b] list, in which colorSpace=’rgb255’ argument has to be added.

  • alpha (float) – The opacity of the circle relative to the background, from 1.0 (opaque) to 0.0 (transparent).

  • blur (float) – The transparency mask that determines the proportion of the patch that will be blurred.

  • **kwargs – Additional arguments passed into psychopy.visual.Circle() or psychopy.visual.GratingStim().

Returns:

In-place modification of the PsychoPy window (No explicit return).

See also

image_circles

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Initiate window
>>> window = visual.Window(size=[800, 600], winType='pygame', color="white")
>>> # Draw circle
>>> pyllusion.psychopy_circle(window, color="yellow", y=0.5)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()
psychopy_line(window, x=0, y=0, x1=None, y1=None, x2=None, y2=None, length=1, size=1, rotate=0, color='black', alpha=0, adjust_width=False, adjust_height=False, **kwargs)[source]

Creates a PsychoPy stimulus of a line.

The *_line functions are meant to facilitate the creation of primitive shapes, in this case, line(s), that can be assembled into illusory stimuli.

This function is intended to create lines similar to image_line() within PsychoPy. It is essentially a wrapper around PsychoPy psychopy.visual.Line(). The difference lies within the names of the arguments and the values that they take (e.g., we use a consistent x-y plane [-1, 1; -1, 1] for the screen “space” with 0 as the center, instead of pixels starting from the corner). The purpose of this wrapper is to have consistent behaviour for functions that are based on the different backends (e.g., PIL, PsychoPy). See the PsychoPy documentation for more information (https://www.psychopy.org/api/visual/line.html).

Parameters:
  • window (object) – A PsychoPy window for displaying one or more stimuli.

  • x (int) – x-coordinates of the center of the line, from -1 to 1.

  • y (int) – y-coordinates of the center of the line, from -1 to 1.

  • x1, x2 (int) – x-coordinates of the ends of the line, from -1 to 1. If not None, x is set to None.

  • y1, y2 (int) – y-coordinates of the ends of the line, from -1 to 1. If not None, y is set to None.

  • length (int) – Length of the line returned.

  • size (int) – Width of the line returned.

  • rotate (float) – The orientation of the line in degrees, 0 being vertical and positive values rotating clockwise.

  • color (Union[list, str]) – The color of the line as single string value or [r, g, b] list, in which colorSpace=’rgb255’ argument has to be added.

  • alpha (float) – The opacity of the line relative to the background, from 1.0 (opaque) to 0.0 (transparent).

  • adjust_width (bool) – If set to True, the x-coordinates of the line can be adjusted to the height and width of the window. Defaults to False.

  • adjust_height (bool) – If set to True, the y-coordinates of the line can be adjusted to the height and width of the window. Defaults to False.

  • **kwargs – Additional arguments passed into psychopy.visual.Line()

Returns:

In-place modification of the PsychoPy window (No explicit return).

See also

image_line

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Initiate window
>>> window = visual.Window(size=[800, 600], winType='pygame', color="white")
>>> # Draw line
>>> pyllusion.psychopy_line(window, x=0, y=0, length=1)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()
psychopy_rectangle(window, x=0, y=0, size_width=1, size_height=1, rotate=0, color='black', outline=0, outline_color='black', alpha=1, adjust_width=False, adjust_height=False, **kwargs)[source]

Creates a PsychoPy stimulus of a rectangle.

The *_rectangle functions are meant to facilitate the creation of primitive shapes, in this case, rectangle(s), that can be assembled into illusory stimuli.

This function is intended to create lines similar to image_rectangle() within PsychoPy. It is essentially a wrapper around PsychoPy psychopy.visual.Rect(). The difference lies within the names of the arguments and the values that they take (e.g., we use a consistent x-y plane [-1, 1; -1, 1] for the screen “space” with 0 as the center, instead of pixels starting from the corner). The purpose of this wrapper is to have consistent behaviour for functions that are based on the different backends (e.g., PIL, PsychoPy). See the PsychoPy documentation for more information (https://www.psychopy.org/api/visual/rect.html).

Parameters:
  • window (object) – A PsychoPy window for displaying one or more stimuli.

  • x (float) – x-coordinates of the center of the rectangle, from -1 to 1.

  • y (float) – y-coordinates of the center of the rectangle, from -1 to 1.

  • size_width (float) – The width of the rectangle.

  • size_height (float) – The height of the rectangle.

  • rotate (float) – The orientation of the rectangle in degrees, 0 being vertical and positive values rotating clockwise.

  • color (Union[list, str]) – The fill color of the rectangle as single string value or [r, g, b] list, in which colorSpace=’rgb255’ argument has to be added.

  • outline (float) – The width of the outline of the rectangle.

  • outline_color (Union[list, str]) – The outline color of the rectangle as single string value or [r, g, b] list, in which colorSpace=’rgb255’ argument has to be added.

  • alpha (float) – The opacity of the rectangle relative to the background, from 1.0 (opaque) to 0.0 (transparent).

  • adjust_width (bool) – If set to True, the width of the rectangle can be adjusted to the height and width of the window. Defaults to False.

  • adjust_height (bool) – If set to True, the height of the rectangle can be adjusted to the height and width of the window. Defaults to False.

  • **kwargs – Additional arguments passed into psychopy.visual.Rect()

Returns:

In-place modification of the PsychoPy window (No explicit return).

See also

image_rectangle

Examples

>>> import pyllusion
>>> from psychopy import visual, event
>>> # Initiate window
>>> window = visual.Window(size=[800, 600], winType='pygame', color="white")
>>> # Draw rectangle
>>> pyllusion.psychopy_rectangle(window, x=0, y=0,
                           size_width=0.5, size_height=0.5,
                           color='white',
                           outline_color='black', outline=3, rotate=1)
>>> # Refresh and close window
>>> window.flip()
>>> event.waitKeys()  # Press any key to close
>>> window.close()

Movement

Pyllusion submodule.

images_to_gif(images, path='mygif.gif', fps=30)[source]
>>> import pyllusion
>>>
>>> pyllusion.image_blobs(n=500)  
 <PIL.Image.Image ...>
motiontransparency_images(parameters=None, width=800, height=500, **kwargs)[source]
>>> import pyllusion
>>>
>>> parameters = pyllusion.motiontransparency_parameters(angle=45, duration=4, n=100, fps=20, speed=2)
>>> images = pyllusion.motiontransparency_images(parameters)  
- 0.00% ...
>>> # pyllusion.images_to_gif(images, path="Transparency_From_Motion.gif", fps=parameters["FPS"])
motiontransparency_parameters(angle=None, n=200, duration=0.5, fps=60, speed=1)[source]
movement_circles(n=50, duration=2, fps=30, width=500, height=500, **kwargs)[source]
>>> import pyllusion
>>>
>>> images = pyllusion.movement_circles(n=50, duration=4, fps=30, color="black", size=0.05)
>>> #pyllusion.images_to_gif(images, path="mygif.gif", fps=30)
movement_matrix(n_frames=10, n=50, angle=None, speed=None, keep_in_window=False, keep_in_circle=False, **kwargs)[source]