Skip to content

Commit

Permalink
forced parallelograms to cover corners - hence updated RHS2007 corrug…
Browse files Browse the repository at this point in the history
…ated mondrians
  • Loading branch information
LynnSchmittwilken committed Jan 9, 2023
1 parent 535fc6f commit 9b4c507
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 48 deletions.
71 changes: 33 additions & 38 deletions stimuli/components/shapes.py
Expand Up @@ -9,7 +9,6 @@
"triangle",
"cross",
"parallelogram",
"transparency",
"wedge",
"annulus",
"disc",
Expand Down Expand Up @@ -97,11 +96,12 @@ def rectangle(


def triangle(
shape=None,
visual_size=None,
ppd=None,
shape=None,
intensity_triangle=0.5,
intensity_background=0.0,
include_corners=True,
):
"""Draw a triangle in the lower left corner
Expand All @@ -117,6 +117,8 @@ def triangle(
intensity value for triangle, by default 1.0
intensity_background : float, optional
intensity value of background, by default 0.5
include_corners : bool
if True, image corners are part of the triangle (default)
Returns
-------
Expand All @@ -136,6 +138,9 @@ def triangle(
line2 = np.linspace(0, width - 1, np.maximum(height, width) * 2).astype(int)
line2 = np.repeat(np.expand_dims(line2, -1), np.maximum(height, width) * 2, 1)
mask[line1, line2] = 1

if not include_corners:
mask = np.abs(np.rot90(mask, 2) - 1)

# Draw
img = np.where(mask, intensity_triangle, intensity_background)
Expand Down Expand Up @@ -232,10 +237,10 @@ def cross(


def parallelogram(
parallelogram_depth,
shape=None,
visual_size=None,
ppd=None,
shape=None,
parallelogram_depth=None,
orientation="horizontal",
intensity_background=1.0,
intensity_parallelogram=0.5,
Expand All @@ -244,20 +249,20 @@ def parallelogram(
Parameters
----------
parallelogram_depth : float
depth of parallelogram (if negative, skewed to the other side)
shape : Sequence[Number, Number], Number, or None (default)
shape [height, width] of image, in pixels
visual_size : Sequence[Number, Number], Number, or None (default)
visual size [height, width] of image, in degrees
ppd : Sequence[Number, Number], Number, or None (default)
pixels per degree [vertical, horizontal]
shape : Sequence[Number, Number], Number, or None (default)
shape [height, width] of image, in pixels
parallelogram_depth : float
depth of parallelogram (if negative, skewed to the other side)
orientation : "vertical" or "horizontal" (default)
along which dimension the parallelogram is skewed
intensity_rectangle : float, optional
intensity value for parallelogram, by default 1.0
intensity_background : float, optional
intensity value of background, by default 0.5
intensity value of background, by default 1.0
intensity_parallelogram : float, optional
intensity value for parallelogram, by default 0.5
Returns
-------
Expand All @@ -273,11 +278,7 @@ def parallelogram(
# if orientation == horizontal, triangles are cut out left and right
# if orientation == vertical, triangles are cut out top and bottom

# Rotate
if orientation == "horizontal":
triangle_size = (visual_size.height, abs(parallelogram_depth))
elif orientation == "vertical":
triangle_size = (abs(parallelogram_depth), visual_size.width)
triangle_size = (visual_size.height, abs(parallelogram_depth))

# Create shapes to create parallelogram
mask = np.ones(shape)
Expand All @@ -287,29 +288,22 @@ def parallelogram(
ppd=ppd,
intensity_background=1,
intensity_triangle=0,
include_corners=False
)["img"]

triangle2 = triangle(
visual_size=triangle_size,
ppd=ppd,
intensity_background=0,
intensity_triangle=1,
)["img"]

if orientation == "horizontal":
mask[0 : triangle1.shape[0], 0 : triangle1.shape[1]] = np.logical_and(
mask[0 : triangle1.shape[0], 0 : triangle1.shape[1]], triangle1
)
mask[0 : triangle1.shape[0], (mask.shape[1] - triangle1.shape[1]) :] = np.logical_and(
mask[0 : triangle1.shape[0], (mask.shape[1] - triangle1.shape[1]) :], triangle2
)
elif orientation == "vertical":
mask[0 : triangle1.shape[0], 0 : triangle1.shape[1]] = np.logical_and(
mask[0 : triangle1.shape[0], 0 : triangle1.shape[1]], triangle2
)
mask[(mask.shape[0] - triangle1.shape[0]) :, 0 : triangle1.shape[1]] = np.logical_and(
mask[(mask.shape[0] - triangle1.shape[0]) :, 0 : triangle1.shape[1]], triangle1
)
triangle1[-1, -1] = 0
triangle2 = np.abs(triangle1-1)

mask[0 : shape[0], 0 : triangle1.shape[1]] = np.logical_and(
mask[0 : shape[0], 0 : triangle1.shape[1]], triangle1
)
mask[0 : shape[0], (mask.shape[1] - triangle2.shape[1]) :] = np.logical_and(
mask[0 : shape[0], (mask.shape[1] - triangle2.shape[1]) :], triangle2
)

# Rotate
if orientation == "vertical":
mask = np.rot90(mask)
mask = np.fliplr(mask)

if parallelogram_depth < 0.0:
mask = np.fliplr(mask)
Expand All @@ -324,6 +318,7 @@ def parallelogram(
"visual_size": visual_size,
"ppd": ppd,
"parallelogram_depth": parallelogram_depth,
"orientation": orientation,
"intensity_background": intensity_background,
"intensity_parallelogram": intensity_parallelogram,
}
12 changes: 2 additions & 10 deletions tests/papers/RHS2007.json
Expand Up @@ -92,8 +92,8 @@
"mask": "482a960756b2775d4e01a7445fd01624"
},
"corrugated_mondrian": {
"img": "2e02782a01a0b5a8060a3403b356f281",
"mask": "4d6bf8e18d60005cfca4f68d6b0bb6a2"
"img": "e057bba4e6816f7a944a97ec3ab06fb4",
"mask": "d1308963fc24274612d28476fcfab7a5"
},
"benary_cross": {
"img": "2865af1cc6d35f7e36400703addd7f2a",
Expand All @@ -110,13 +110,5 @@
"todorovic_benary1_2_3_4": {
"img": "5796edd6dc6153a2a47f6b9a06ed698d",
"mask": "763e018b2d95aa97394c4d19214ac9f6"
},
"bullseye_thin": {
"img": "599c481aa866113ad0512b593ceae8d9",
"mask": "e29258d4c0d70e818978a766d6e0d008"
},
"bullseye_thick": {
"img": "c74d91f7476887b2ab3d7ebd35f4dd52",
"mask": "0f6dbe6cf9e1fd42ad43217c8fa0a8e3"
}
}

0 comments on commit 9b4c507

Please sign in to comment.