Skip to content

Commit

Permalink
added tests for modelfest and updated many component-masks for that; …
Browse files Browse the repository at this point in the history
…updated RHS-json with new bullseyes
  • Loading branch information
LynnSchmittwilken committed Jan 13, 2023
1 parent 90b2bcb commit 992dbab
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 42 deletions.
2 changes: 1 addition & 1 deletion stimuli/components/circular.py
Expand Up @@ -510,7 +510,7 @@ def bessel(

stim = {
"img": img,
"mask": None,
"mask": np.zeros(shape).astype(int),
"visual_size": base["visual_size"],
"ppd": base["ppd"],
"shape": base["shape"],
Expand Down
4 changes: 1 addition & 3 deletions stimuli/components/edges.py
Expand Up @@ -52,7 +52,7 @@ def step_edge(
img = np.where(base["rotated"] < base["rotated"].mean(), img, intensity_edges[1])
mask = np.ones(shape)
mask = np.where(base["rotated"] < base["rotated"].mean(), mask, 2)

stim = {
"img": img,
"mask": mask.astype(int),
Expand Down Expand Up @@ -117,9 +117,7 @@ def gaussian_edge(

img = stim["img"] - intensity_background
img = img * window["img"] + intensity_background
mask = stim["mask"] * window["img"]
stim["img"] = img
stim["mask"] = mask.astype(int)
stim["sigma"] = sigma
stim["intensity_background"] = intensity_background
return stim
Expand Down
2 changes: 2 additions & 0 deletions stimuli/components/gaussians.py
@@ -1,5 +1,6 @@
import numpy as np
from stimuli.components import image_base
from stimuli.components.shapes import disc


__all__ = [
Expand Down Expand Up @@ -71,6 +72,7 @@ def gaussian(

stim = {
"img": gaussian,
"mask": np.zeros(shape).astype(int),
"sigma": sigma,
"rotation": rotation,
"visual_size": base["visual_size"],
Expand Down
1 change: 1 addition & 0 deletions stimuli/components/lines.py
Expand Up @@ -200,6 +200,7 @@ def dipole(
)

stim1["img"] = stim1["img"] + stim2["img"]
stim1["mask"] = (stim1["mask"] + stim2["mask"]*2).astype(int)

return stim1

Expand Down
2 changes: 1 addition & 1 deletion stimuli/papers/__init__.py
@@ -1 +1 @@
__all__ = ["RHS2007", "domijan2015", "murray2020"]
__all__ = ["RHS2007", "domijan2015", "murray2020", "carney1999"]
115 changes: 78 additions & 37 deletions stimuli/papers/carney1999.py
Expand Up @@ -32,6 +32,7 @@

import numpy as np
import pandas as pd
from pathlib import Path

from stimuli.components import grating, gaussians, shapes, checkerboard, lines
from stimuli.components.edges import gaussian_edge
Expand Down Expand Up @@ -91,7 +92,7 @@

mean_lum = 0.5

df = pd.read_csv("carney1999_data.csv", header=None)
df = pd.read_csv(Path(__file__).parents[0] / "carney1999_data.csv", header=None)
participants = df[0]


Expand Down Expand Up @@ -1140,14 +1141,13 @@ def Subthreshold22(ppd=PPD):
stim1 = grating.gabor(**params, frequency=2)
stim2 = grating.gabor(**params, frequency=2*np.sqrt(2))

stim1 = {
"img": stim1["img"]/2 + stim2["img"]/2,
"mask2": stim2["mask"],
"edges2": stim2["edges"],
"frequency2": stim2["frequency"],
"bar_width2": stim2["bar_width"],
"n_bars2": stim2["n_bars"],
}
stim1["img"] = stim1["img"]/2 + stim2["img"]/2
stim1["mask"] = stim1["mask"].astype(int)
stim1["mask2"] = stim2["mask"].astype(int)
stim1["edges2"] = stim2["edges"]
stim1["frequency2"] = stim2["frequency"]
stim1["bar_width2"] = stim2["bar_width"]
stim1["n_bars2"] = stim2["n_bars"]

v = 85
experimental_data = {
Expand Down Expand Up @@ -1196,14 +1196,12 @@ def Subthreshold23(ppd=PPD):
stim1 = grating.gabor(**params, frequency=2)
stim2 = grating.gabor(**params, frequency=4)

stim1 = {
"img": stim1["img"]/2 + stim2["img"]/2,
"mask2": stim2["mask"],
"edges2": stim2["edges"],
"frequency2": stim2["frequency"],
"bar_width2": stim2["bar_width"],
"n_bars2": stim2["n_bars"],
}
stim1["img"] = stim1["img"]/2 + stim2["img"]/2
stim1["mask2"] = stim2["mask"].astype(int)
stim1["edges2"] = stim2["edges"]
stim1["frequency2"] = stim2["frequency"]
stim1["bar_width2"] = stim2["bar_width"]
stim1["n_bars2"] = stim2["n_bars"]

v = 89
experimental_data = {
Expand Down Expand Up @@ -1252,14 +1250,12 @@ def Subthreshold24(ppd=PPD):
stim1 = grating.gabor(**params, frequency=4)
stim2 = grating.gabor(**params, frequency=4*np.sqrt(2))

stim1 = {
"img": stim1["img"]/2 + stim2["img"]/2,
"mask2": stim2["mask"],
"edges2": stim2["edges"],
"frequency2": stim2["frequency"],
"bar_width2": stim2["bar_width"],
"n_bars2": stim2["n_bars"],
}
stim1["img"] = stim1["img"]/2 + stim2["img"]/2
stim1["mask2"] = stim2["mask"].astype(int)
stim1["edges2"] = stim2["edges"]
stim1["frequency2"] = stim2["frequency"]
stim1["bar_width2"] = stim2["bar_width"]
stim1["n_bars2"] = stim2["n_bars"]

v = 93
experimental_data = {
Expand Down Expand Up @@ -1308,14 +1304,12 @@ def Subthreshold25(ppd=PPD):
stim1 = grating.gabor(**params, frequency=4)
stim2 = grating.gabor(**params, frequency=8)

stim1 = {
"img": stim1["img"]/2 + stim2["img"]/2,
"mask2": stim2["mask"],
"edges2": stim2["edges"],
"frequency2": stim2["frequency"],
"bar_width2": stim2["bar_width"],
"n_bars2": stim2["n_bars"],
}
stim1["img"] = stim1["img"]/2 + stim2["img"]/2
stim1["mask2"] = stim2["mask"].astype(int)
stim1["edges2"] = stim2["edges"]
stim1["frequency2"] = stim2["frequency"]
stim1["bar_width2"] = stim2["bar_width"]
stim1["n_bars2"] = stim2["n_bars"]

v = 97
experimental_data = {
Expand Down Expand Up @@ -1759,7 +1753,7 @@ def GaborString34(ppd=PPD):
return {**stim1, "experimental_data": experimental_data}


def Noise35(ppd=PPD):
def Noise35_random(ppd=PPD):
"""Noise35 - binary noise x Gaussian, Carney et al (1999)
Gaussian window: sy=sx=0.5 deg
Expand Down Expand Up @@ -1800,6 +1794,52 @@ def Noise35(ppd=PPD):
return {**stim, "experimental_data": experimental_data}


def Noise35(ppd=PPD):
"""Noise35 - binary noise x Gaussian, Carney et al (1999)
Gaussian window: sy=sx=0.5 deg
Parameters
----------
ppd : Sequence[Number, Number], Number, or None
pixels per degree [vertical, horizontal]
Returns
-------
dict[str, Any]
dict with the stimulus (key: "img") and additional keys containing
stimulus parameters
References
-----------
Carney, T., Klein, S. A., Tyler, C. W., Silverstein, A. D., Beutter, B., Levi, D.,
... & Eckstein, M. P. (1999). Development of an image/threshold database
for designing and testing human vision models. Proceedings of SPIE, 3644,
542-551. https://doi.org/10.1117/12.348473
"""
# Read natural image from Modelfest
img = read_tif(Path(__file__).parents[0] / "carney1999_noise.tif")
img = img / img.max()

stim = {
"img": img,
"mask": np.zeros(img.shape).astype(int),
"visual_size": (256/PPD, 256/PPD),
"shape": img.shape,
"ppd": PPD,
"intensity_range": (img.min(), img.max()),
}

v = 169
experimental_data = {
"participants": participants,
"thresholds1": df[v],
"thresholds2": df[v+1],
"thresholds3": df[v+2],
"thresholds4": df[v+3],
}
return {**stim, "experimental_data": experimental_data}


def Orientation36(ppd=PPD):
"""Orientation36 - oriented Gabor, Carney et al (1999)
Frequency: 4 cpd
Expand Down Expand Up @@ -2157,11 +2197,12 @@ def NaturalScene43(ppd=PPD):
"""

# Read natural image from Modelfest
img = read_tif("carney1999_natural_scene.tif")
img = read_tif(Path(__file__).parents[0] / "carney1999_natural_scene.tif")
img = img / img.max()

stim = {
"img": img,
"mask": np.zeros(img.shape).astype(int),
"visual_size": (256/PPD, 256/PPD),
"shape": img.shape,
"ppd": PPD,
Expand Down Expand Up @@ -2203,7 +2244,7 @@ def compare(o1, s1, filename):
def compare_all():
for stim_name in __all__:
func = globals()[stim_name]
o1 = read_tif("./modelfest/" + stim_name + ".tif")
o1 = read_tif(str(Path(__file__).parents[0]) + "/modelfest/" + stim_name + ".tif")
s1 = func()["img"]
compare(o1, s1, stim_name + ".png")

Expand All @@ -2212,5 +2253,5 @@ def compare_all():
from stimuli.utils import plot_stimuli

stims = gen_all(skip=True)
plot_stimuli(stims, mask=False)
plot_stimuli(stims, mask=True)
# compare_all()
Binary file added stimuli/papers/carney1999_noise.tif
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/papers/RHS2007.json
Expand Up @@ -110,5 +110,13 @@
"todorovic_benary1_2_3_4": {
"img": "5796edd6dc6153a2a47f6b9a06ed698d",
"mask": "763e018b2d95aa97394c4d19214ac9f6"
},
"bullseye_thin": {
"img": "e784faee64ccbf1f2b90fad8fb653bc4",
"mask": "e6b7638c7de948a3d4f1ad743f5d144a"
},
"bullseye_thick": {
"img": "8e9a74ed64b1189b8aa5ad99166f243e",
"mask": "fd836e38f48a08311ba4603c672d109d"
}
}

0 comments on commit 992dbab

Please sign in to comment.