Using shape elements to frame a picture


Author
Message
AKrishna
AKrishna
Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)
Group: Forum Members
Posts: 93, Visits: 281
I'm working on an approach-avoidance task with some vertically and some horizontally oriented stimuli. Participants will be asked to respond to the color of the picture's frame. However, I've run into an issue I can't seem to fix while building this.

I'm trying to dynamically control the size of a rectangular shape element based on the size of the picture stimulus. My tactic is to adjust the picture stimulus' size on the fly based on the filename (which identifies whether the picture is horizontally or vertically oriented), then set the frame's size to slightly larger. But when I start the program, depending on the randomly selected sequence of pictures, the frame sometimes fits both and sometimes only fits the vertical orientation, apparently because the horizontal picture is presented smaller than it should be.

I've tried playing around with onprepare instead of ontrialbegin, but nothing seems to help. I'd appreciate a fresh set of eyes on the problem - maybe I'm just missing something in my code or about how Inquisit handles picture presentation and stimulus-bounding rectangles?

Here's an example:
<block show>
/ trials = [1-2 = showpic]

</block>




<trial showpic>
/ ontrialbegin = [
    if (search(picture.pic.item(picture.pic.currentindex),"_h") > -1) {
        values.hmultiplier = 3/4; values.vmultiplier = 1
    }
    else if (search(picture.pic.item(picture.pic.currentindex),"_h") == -1) {
        values.hmultiplier = 4/3; values.vmultiplier = 1
    }
]
/ stimulustimes = [0 = frame, pic, debug]
/ validresponse = ( " ")
</trial>

<text debug>
/ items = ("Item: <%picture.pic.item(picture.pic.currentindex)%>
Search: <%search(picture.pic.item(picture.pic.currentindex),~"_h~")%>")
/ position = (50%, 20%)
</text>


/ onprepare = [
    if (search(picture.pic.item(picture.pic.currentindex),"_h") > -1) {
        values.hmultiplier = 3/4; values.vmultiplier = 1
    }
    else if (search(picture.pic.item(picture.pic.currentindex),"_h") == -1) {
        values.hmultiplier = 4/3; values.vmultiplier = 1
    }
]        
<picture pic>
/ items = ("Animals_177_h.jpg","Animals_166_v.jpg")
/ size = (values.hmultiplier*values.sizer, values.vmultiplier*values.sizer))
/ erase = true(white)
</picture>


/ onprepare = [
    shape.frame.widthpx = 1px*(picture.pic.widthpx)+20px;
    shape.frame.heightpx = 1px*(picture.pic.heightpx)+20px
]

<shape frame>
/ size = (1px*(picture.pic.widthpx)+20px, 1px*(picture.pic.heightpx)+20px)
/ shape = rectangle
/ color = cornflowerblue

/ position = (50%, 50%)
</shape>


<values>
/sizer = 0.3px*display.canvasheight
/hmultiplier = 0.1
/vmultiplier = 0.1
</values>


/ windowsize = (1980px, 1080px)
<defaults>
</defaults>


Note that several attributes are outside the relevant elements - these indicate some of the options I have tried out and that didn't produce the desired results. The required pictures are available under these links (I didn't upload them because they're part of a picture database, so I want to time-limit sharing them).
https://gigamove.rwth-aachen.de/de/download/d78e431156a12daeb263044e238ffb92
https://gigamove.rwth-aachen.de/de/download/f84d4583ab4b84eda798de97de3ca932



Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
AKrishna - 11/27/2023
I'm working on an approach-avoidance task with some vertically and some horizontally oriented stimuli. Participants will be asked to respond to the color of the picture's frame. However, I've run into an issue I can't seem to fix while building this.

I'm trying to dynamically control the size of a rectangular shape element based on the size of the picture stimulus. My tactic is to adjust the picture stimulus' size on the fly based on the filename (which identifies whether the picture is horizontally or vertically oriented), then set the frame's size to slightly larger. But when I start the program, depending on the randomly selected sequence of pictures, the frame sometimes fits both and sometimes only fits the vertical orientation, apparently because the horizontal picture is presented smaller than it should be.

I've tried playing around with onprepare instead of ontrialbegin, but nothing seems to help. I'd appreciate a fresh set of eyes on the problem - maybe I'm just missing something in my code or about how Inquisit handles picture presentation and stimulus-bounding rectangles?

Here's an example:
<block show>
/ trials = [1-2 = showpic]

</block>




<trial showpic>
/ ontrialbegin = [
    if (search(picture.pic.item(picture.pic.currentindex),"_h") > -1) {
        values.hmultiplier = 3/4; values.vmultiplier = 1
    }
    else if (search(picture.pic.item(picture.pic.currentindex),"_h") == -1) {
        values.hmultiplier = 4/3; values.vmultiplier = 1
    }
]
/ stimulustimes = [0 = frame, pic, debug]
/ validresponse = ( " ")
</trial>

<text debug>
/ items = ("Item: <%picture.pic.item(picture.pic.currentindex)%>
Search: <%search(picture.pic.item(picture.pic.currentindex),~"_h~")%>")
/ position = (50%, 20%)
</text>


/ onprepare = [
    if (search(picture.pic.item(picture.pic.currentindex),"_h") > -1) {
        values.hmultiplier = 3/4; values.vmultiplier = 1
    }
    else if (search(picture.pic.item(picture.pic.currentindex),"_h") == -1) {
        values.hmultiplier = 4/3; values.vmultiplier = 1
    }
]        
<picture pic>
/ items = ("Animals_177_h.jpg","Animals_166_v.jpg")
/ size = (values.hmultiplier*values.sizer, values.vmultiplier*values.sizer))
/ erase = true(white)
</picture>


/ onprepare = [
    shape.frame.widthpx = 1px*(picture.pic.widthpx)+20px;
    shape.frame.heightpx = 1px*(picture.pic.heightpx)+20px
]

<shape frame>
/ size = (1px*(picture.pic.widthpx)+20px, 1px*(picture.pic.heightpx)+20px)
/ shape = rectangle
/ color = cornflowerblue

/ position = (50%, 50%)
</shape>


<values>
/sizer = 0.3px*display.canvasheight
/hmultiplier = 0.1
/vmultiplier = 0.1
</values>


/ windowsize = (1980px, 1080px)
<defaults>
</defaults>


Note that several attributes are outside the relevant elements - these indicate some of the options I have tried out and that didn't produce the desired results. The required pictures are available under these links (I didn't upload them because they're part of a picture database, so I want to time-limit sharing them).
https://gigamove.rwth-aachen.de/de/download/d78e431156a12daeb263044e238ffb92
https://gigamove.rwth-aachen.de/de/download/f84d4583ab4b84eda798de97de3ca932



Apart from the fundamental problem that using currentindex won't work (no selection has happened at this point), I have a feeling the math is wrong?

With

/ ontrialbegin = [
if (search(picture.pic.item(picture.pic.currentindex),"_h") > -1) {
values.hmultiplier = 3/4; values.vmultiplier = 1
}
else if (search(picture.pic.item(picture.pic.currentindex),"_h") == -1) {
values.hmultiplier = 4/3; values.vmultiplier = 1
}
]


and

<picture pic>
/ items = ("Animals_177_h.jpg","Animals_166_v.jpg")
/ size = (values.hmultiplier*values.sizer, values.vmultiplier*values.sizer))
/ erase = true(white)
</picture>

<values>
/sizer = 0.3px*display.canvasheight
...
</values>


and, just for the sake of example, assuming a canvasheight of 900px, the horizontal case always works out to


width: (0.3 * 900) * (3/4) = 270 * 0.75 = 202.5px
height: (0.3 * 900) * 1 = 270 * 1 =  270px
size aspect ratio: 3/4
image dimensions of Animals_177_h.jpg: 1600 x 1200 px
image aspect ratio: 4/3


and the vertical case always works out to

width: (0.3 * 900) * (4/3) = 270 * 1.33 = 360px
height: (0.3 * 900) * 1 = 270 * 1 = 270px
size aspect ratio: 4/3
image dimensions of Animals_166_v.jpg: 1200 x 1600 px
image aspect ratio: 3/4

So it seems to me you have things backwards?

Anyway, if you fix that and make sure the to-be-displayed image item is actually known /ontrialbegin, then things should work.

<block show>
/ trials = [1-2 = showpic]
</block>

<list picitemlist>
/ poolsize = 2
</list>

<trial showpic>
/ ontrialbegin = [
    values.picitemnumber = list.picitemlist.nextindex;
    if (search(picture.pic.item(values.picitemnumber),"_h") > -1) {
        values.hmultiplier = 4/3; values.vmultiplier = 1;
    }
    else if (search(picture.pic.item(values.picitemnumber),"_h") == -1) {
        values.hmultiplier = 3/4; values.vmultiplier = 1;
    };
]
/ stimulustimes = [0 = clearscreen, frame, pic]
/ validresponse = (" ")
</trial>

<expressions>
/ picheight = 1px*values.vmultiplier*values.sizer
/ picwidth = 1px*values.hmultiplier*values.sizer
</expressions>

<picture pic>
/ items = ("Animals_177_h.jpg","Animals_166_v.jpg")
/ select = values.picitemnumber
/ height = expressions.picheight
/ width = expressions.picwidth
/ erase = true(white)
</picture>

<shape frame>
/ height = expressions.picheight + 20
/ width = expressions.picwidth + 20
/ shape = rectangle
/ color = cornflowerblue
/ position = (50%, 50%)
</shape>

<values>
/sizer = 0.3px*display.canvasheight
/hmultiplier = 0.1
/vmultiplier = 0.1
/picitemnumber = 1
</values>


Edited 6 Months Ago by Dave
AKrishna
AKrishna
Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)Distinguished Member (3.2K reputation)
Group: Forum Members
Posts: 93, Visits: 281
Cheers. The "currentitem" vs. "nextitem" issue was what was stumping me; I thought I'd made some progress because it was working sometimes, but that only happened because of the "delayed" fit. So I didn't even twig that my math was the wrong was around...

Thanks as always for the swift help!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search