Example #1
0
def unify_localLum():
    ## template image
    templateImg = "../white_box2"
    ## load template image to array
    templateImg_mat = image_to_array(templateImg)

    ## masking
    mask43_fname = "../mask_ShLi_43"  # standard: within shadow, light check
    mask35_fname = "../mask_PlDa_35"  # comparison dark: outside shadow, dark check

    ## load mask images to array
    mask43 = image_to_array(mask43_fname)
    mask35 = image_to_array(mask35_fname)

    ## set entire checks with values read from center coordinates of each target check
    # S, check 43 : position=(428,585)
    # CD, check 35 : position=(337,442)
    # CL, check 32 : position=(477,435)
    # CDD, check 26 : position= (294,306)
    # CDD, check 24 : position= (383,295)
    templateImg_mat[mask43 != 0] = templateImg_mat[428, 585]
    templateImg_mat[mask35 != 0] = templateImg_mat[428, 585]

    # save the rendered image
    array_to_image(templateImg_mat, "../renTemplate", "png")
Example #2
0
def drawImg(inputImg, radius, sLum, cdLum):
    curr_image2 = image_to_array(inputImg)
    curr_image = curr_image2 / 255.0
    elipse = make_ellipse(radius)
    add_increment(stimulus=curr_image, increment=elipse * (sLum / 255.0), position=(428, 585))
    add_increment(stimulus=curr_image, increment=elipse * (cdLum / 255.0), position=(337, 442))

    return curr_image
Example #3
0
def unify_localLum(a):
    ## template image
    templateImg = "../template"
    ## load template image to array
    templateImg_mat = image_to_array(templateImg)

    ## masking
    mask43_fname = "../mask_ShLi_43"  # standard: within shadow, light check
    mask35_fname = "../mask_PlDa_35"  # comparison dark: outside shadow, dark check

    ## load mask images to array
    mask43 = image_to_array(mask43_fname)
    mask35 = image_to_array(mask35_fname)

    ## set entire checks with values read from center coordinates of each target check
    # S, check 43 : position=(215,292)
    # CD, check 35 : position=(170,220)
    # CL, check 32 : position=(239,219)
    # CDD, check 26 : position= (148,151)
    # CDD, check 24 : position= (191,146)
    templateImg_mat[mask43 != 0] = templateImg_mat[215, 292]
    templateImg_mat[mask35 != 0] = templateImg_mat[170, 220]

    # 0 for dark comparison, 1 for light comarison
    if a == 1:
        mask32_fname = "../mask_ShLi_32"  # block1 reference light: within shadow, light check
        mask32 = image_to_array(mask32_fname)
        templateImg_mat[mask32 != 0] = templateImg_mat[239, 219]
    if a == 0:
        mask24_fname = "../mask_PlDa_24"  # block2 reference dark: outside shadow, dark check (near the shadow)
        mask24 = image_to_array(mask24_fname)
        templateImg_mat[mask24 != 0] = templateImg_mat[191, 146]
        # ~ mask26_fname = '../mask_PlDa_26' # block2 reference dark: outside shadow, dark check (by the upper edge)
        # ~ mask26 = image_to_array(mask26_fname)
        # ~ templateImg_mat[mask26 != 0] = templateImg_mat[148,151]

        # save the rendered image
    array_to_image(templateImg_mat, "../renTemplate", "png")
Example #4
0
#~ def main(a, b):
	#~ print str(a) + "_" + str(b)
#~ 
#~ if __name__ == '__main__':
	#~ initials = raw_input(prompt="initals")
	#~ check01 = raw_input(prompt="0 : targets on dark check, 1: targets on light check")
	#~ main(initials, check01)

scd_pairs = pd.read_csv('../lut.csv', sep=" ")
#~ plt.scatter(scd_pairs['IntensityIn'], scd_pairs['IntensityOut'])
#~ plt.scatter(scd_pairs['IntensityIn'], scd_pairs['Luminance'])
#~ plt.scatter(scd_pairs['IntensityOut'], scd_pairs['Luminance'])
#~ plt.show()
InIn = scd_pairs['IntensityIn'].values
InOut = scd_pairs['IntensityOut'].values
Lum = scd_pairs['Luminance'].values


	# S, check 43 : position=(215,292) 
	# CD, check 35 : position=(170,220)
	# CL, check 32 : position=(239,219)
	# CDD, check 26 : position= (148,151)
	# CDD, check 24 : position= (191,146)

img = image_to_array('../renTemplate')
x= np.flipud(img[215,292]/255.0)
y= np.flipud(img[170,220]/255.0)


print np.interp(x, InIn, InOut)
def main(sbj, blk):
	#~ observer_id  = raw_input ('Please write the subject\'s initials: ')
	#~ os.path.isfile(observer_id*)
	### HRL Parameters ###


	# Here we define all the paremeters required to instantiate an HRL object.

	# Which devices we wish to use in this experiment. See the
	# pydoc documentation for a list of # options.
	graphics='datapixx' # 'datapixx' is another option
	inputs='responsepixx' # 'responsepixx' is another option
	photometer=None
	scrn = 1

	# Screen size
	wdth = 1024
	hght = 768
	
	# Whether or not to use fullscreen. You probably want to do this when
	# actually running experiments, but when just developing one, fullscreen
	# locks out access to the rest of the computer, so you'll probably want to
	# turn this off.
	fs = True

	# Design and result matrix information. This allows us the to use the HRL
	# functionality for automatically reading a design matrix, and
	# automatically generating a result matrix. See 'pydoc hrl.hrl' for more
	# information about these.

	# Design and Result matrix files names
	#~ designFname = 
	#~ dfl = '../design/' + designFname + '.csv'
	#~ dfl = '../design/%s_design.csv' %(observer_id)
	#~ rfl = '../results/%s_results.csv' %(observer_id)
	
	if blk == 0:
		dfl = '../design/2afc_design_Dark_' + sbj + '.csv'
		rfl = '../results/2afc_results_Dark_' + sbj + '.csv'
	if blk == 1:
		dfl = '../design/2afc_design_Light_' + sbj + '.csv'
		rfl = '../results/2afc_results_Light_' + sbj + '.csv'
	
	# The names of the fields in the results matrix. In each loop of the
	# script, we write another line of values to results.csv under these
	# headings.
	rhds = ['Trial', 'LumTarget', 'LumMatch', 'LT-LM', 'LumComp', '%deviance', 'Choice', 'RT']

	# Pass this to HRL if we want to use gamma correction.
	lut = '../stimuli/lut.csv'

	# Create the hrl object with the above fields. All the default argument names are
	# given just for illustration.
	hrl = HRL(graphics=graphics,
			  inputs=inputs,
			  photometer=photometer,
			  wdth=wdth,
			  hght=hght,
			  bg=0,
			  dfl=dfl,
			  rfl=rfl,
			  rhds=rhds,
			  fs=fs,
			  scrn=scrn,
			  lut=lut )

	# hrl.results is a dictionary which is automatically created by hrl when
	# give a list of result fields. This can be used to easily write lines to
	# the result file, as will be seen later.
	hrl.results['Trial'] = 0
	
	btn = None
	t = 0
	escp = False
	
	#instruction screen 
	frmInst = hrl.graphics.newTexture(np.array([[1]]))
	frmInst.draw((0,0), (wdth,hght))
	hrl.graphics.flip(clr=True)
	while ((btn != 'Space') & (escp != True)):
		(btn,t1) = hrl.inputs.readButton()
		if btn == 'Escape':
			escp = True
			raise Exception('experiment terminated by the subject')
	
	### Experiment setup ###

	# texture creation in buffer : stimulus	   I DO NOT NEED A BUFFERED IMAGE TO DRAW ON
		
	### Core Loop ###

	# hrl.designs is an iterator over all the lines in the specified design
	# matrix, which was loaded at the creation of the hrl object. Looping over
	# it in a for statement provides a nice way to run each line in a design
	# matrix. The fields of each design line (dsgn) are drawn from the design
	# matrix in the design file (design.csv).
	for dsgn in hrl.designs:
		# Here we save the values of the design line with appropriately cast
		# types and simple names.
		LumS = float(dsgn['Lum_S'])
		LumCD = float(dsgn['Lum_CD'])
		LumCL = float(dsgn['Lum_CL'])

		if blk == 1:
			img_fname = '../stimuli/' + sbj +'/lS%d_CD%d_CL%d' %(int(LumS), int(LumCD), int(LumCL))
		if blk == 0:
			img_fname = '../stimuli/' +sbj + '/dS%d_CD%d_CDD%d' %(int(LumS), int(LumCD), int(LumCL))
		#~ curr_image = image_to_array(img_fname)
		curr_image2 = image_to_array(img_fname)
		curr_image  = normalize_image2(curr_image2, 0, 1)
		
		# prestimulus fixation 
		frmFix = hrl.graphics.newTexture(np.array([[float(120.0/255.0)]]))
		frmFix.draw((0,0), (wdth,hght))
		hrl.graphics.flip(clr=False)
		time.sleep(0.5)
		
		# And finally we preload some variables to prepare for our button
		# reading loop.
		
		# stimulus presentation
		#~ frm1 = hrl.graphics.newTexture(curr_image)
		frm1 = hrl.graphics.newTexture(curr_image)
		frm1.draw((0,0),(wdth,hght)) 
		hrl.graphics.flip(clr=True)
		time.sleep(0.25)
		#~ time.sleep(1.0)
		
		# response fixation
		frmFix.draw((0,0), (wdth,hght))
		if hrl.results['Trial'] > 99:
			nte2 = hrl.results['Trial'] / 100
			nte1 = hrl.results['Trial'] / 10 - nte2*10
			nte0 = hrl.results['Trial'] %10
			fileN = 'testingImg_%d' %(nte1)
			fileN2 = 'testingImg_%d' %(nte0)
			fileN3 = 'testingImg_%d' %(nte2)
			nT = normalize_image2(image_to_array(fileN),0,1)
			nT2 = normalize_image2(image_to_array(fileN2),0,1)
			nT3 = normalize_image2(image_to_array(fileN3),0,1)
			hrl.graphics.newTexture(nT).draw((25,0), (20,28))
			hrl.graphics.newTexture(nT2).draw((50,0), (20,28)) 
			hrl.graphics.newTexture(nT3).draw((5,0), (20,28)) 
			hrl.graphics.flip(clr=True) 
			
		elif hrl.results['Trial'] > 9:
			nte1 = hrl.results['Trial'] / 10
			nte0 = hrl.results['Trial'] %10
			fileN = 'testingImg_%d' %(nte1)
			filen2 = 'testingImg_%d' %(nte0)
			nT = normalize_image2(image_to_array(fileN),0,1)
			nT2 = normalize_image2(image_to_array(filen2),0,1)
			hrl.graphics.newTexture(nT).draw((5,0), (20,28))
			hrl.graphics.newTexture(nT2).draw((25,0), (20,28)) 
			hrl.graphics.flip(clr=True) 
			
		else:
			fileN = 'testingImg_%d' %(hrl.results['Trial'])
			nT = normalize_image2(image_to_array(fileN), 0, 1)
			hrl.graphics.newTexture(nT).draw((5,0), (20,28)) 
			hrl.graphics.flip(clr=True)
			
		### Input Loop ####
		
		# Until the user finalizes their luminance choice for the central
		# circle, or pressed escape...
		
		# The button pressed
		btn = None
		# The time it took to decide on which pair is more different
		t = 0
		# Whether escape was pressed
		escp = False
		
		while ((btn != 'Space') & (escp != True)):

			# Read the next button press
			(btn,t1) = hrl.inputs.readButton()
			# Add the time it took to press to the decision time
			t += t1
			# Respond to the pressed button
			if blk == 0:
				if btn == 'Left': # if CDD-CD-S, then Left = CDD-CD looks more similar
								  # if CD-S-CL , then Left = CD- S  looks more similar 
					hrl.results['Trial'] += 1
					hrl.results['LumTarget'] = LumS
					hrl.results['LumMatch'] = LumCD
					hrl.results['LT-LM'] = LumS-LumCD
					hrl.results['LumComp'] = LumCL
					hrl.results['%deviance'] = np.round(((LumCL-LumCD)/LumCD)*100, 0)
					hrl.results['Choice'] = 0
					hrl.results['RT'] = t
					hrl.writeResultLine()
					break
				elif btn == 'Right': # if CDD-CD-S, then Right = CD-S looks more similar
									 # if CD-S-CL , then Right = S- CL  looks more similar 
					hrl.results['Trial'] += 1
					hrl.results['LumTarget'] = LumS
					hrl.results['LumMatch'] = LumCD
					hrl.results['LT-LM'] = LumS-LumCD
					hrl.results['LumComp'] = LumCL
					hrl.results['Choice'] = 1
					hrl.results['%deviance'] = np.round(((LumCL-LumCD)/LumCD)*100, 0)
					hrl.results['RT'] = t
					hrl.writeResultLine()
					break
				elif btn == 'Escape':
					escp = True
					break
			if blk == 1:
				if btn == 'Down': # if CDD-CD-S, then Left = CDD-CD looks more similar
								  # if CD-S-CL , then Left = CD- S  looks more similar 
					hrl.results['Trial'] += 1
					hrl.results['LumTarget'] = LumS
					hrl.results['LumMatch'] = LumCD
					hrl.results['LT-LM'] = LumS-LumCD
					hrl.results['LumComp'] = LumCL
					hrl.results['%deviance'] = np.round(((LumCL-LumCD)/LumCD)*100, 0)
					hrl.results['Choice'] = 0
					hrl.results['RT'] = t
					hrl.writeResultLine()
					break
				elif btn == 'Up': # if CDD-CD-S, then Right = CD-S looks more similar
									 # if CD-S-CL , then Right = S- CL  looks more similar 
					hrl.results['Trial'] += 1
					hrl.results['LumTarget'] = LumS
					hrl.results['LumMatch'] = LumCD
					hrl.results['LT-LM'] = LumS-LumCD
					hrl.results['LumComp'] = LumCL
					hrl.results['Choice'] = 1
					hrl.results['%deviance'] = np.round(((LumCL-LumCD)/LumCD)*100, 0)
					hrl.results['RT'] = t
					hrl.writeResultLine()
					break
				elif btn == 'Escape':
					escp = True
					break
		# We print the trial number simply to keep track during an experiment
		print hrl.results['Trial']
		
		# If escape has been pressed we break out of the core loop
		if escp:
			print "Session cancelled"
			break
				
	# And the experiment is over!
	hrl.close()
	print "session complete"
Example #6
0
def main(sbj):
    ### Argument Parser ###

    # Here we define all the paremeters required to instantiate an HRL object.

    # Which devices we wish to use in this experiment. See the
    # pydoc documentation for a list of # options.
    graphics = "datapixx"  # 'datapixx' is another option
    inputs = "responsepixx"  # 'responsepixx' is another option
    scrn = 1
    photometer = None

    # Screen size
    wdth = 1024
    hght = 768

    # Whether or not to use fullscreen. You probably want to do this when
    # actually running experiments, but when just developing one, fullscreen
    # locks out access to the rest of the computer, so you'll probably want to
    # turn this off.
    fs = True

    # Pass this to HRL if we want to use gamma correction.
    lut = "../lut.csv"

    # Design and result matrix information. This allows us the to use the HRL
    # functionality for automatically reading a design matrix, and
    # automatically generating a result matrix. See 'pydoc hrl.hrl' for more
    # information about these.

    dfl = "../design/kl/test_design_kl_1.csv"
    # ~ rfl = '../results/base/test_results_onDark_' + subject + '.csv'
    # ~ rhds = ['Trial', 'target', 'LumT', 'LumM_start', 'LumM_end', 'RT']
    hrl = HRL(
        graphics=graphics, inputs=inputs, photometer=photometer, scrn=scrn, wdth=wdth, hght=hght, bg=0, dfl=dfl, fs=fs
    )

    unify_localLum(1)
    curr_image2 = image_to_array("../renTemplate")
    curr_image = normalize_image2(curr_image2, 0, 1)

    for dsgn in hrl.designs:
        LumS = float(dsgn["Lum_S"])
        LumCD = float(dsgn["Lum_CD"])
        LumCL = float(dsgn["Lum_CL"])

        # ~ nte1 = hrl.results['Trial'] / 10
        # ~ nte0 = hrl.results['Trial'] %10
        # ~ fileN = 'testingImg_%d' %(nte1)
        # ~ filen2 = 'testingImg_%d' %(nte0)
        # ~ nT = normalize_image2(image_to_array(fileN),0,1)
        # ~ nT2 = normalize_image2(image_to_array(filen2),0,1)
        # ~ hrl.graphics.newTexture(nT).draw((5,0), (20,28))
        # ~ hrl.graphics.newTexture(nT2).draw((25,0), (20,28))

        # ~ img_fname = '../stimuli/' + sbj +'/klS%d_CD%d_CL%d' %(int(LumS), int(LumCD), int(LumCL))
        # ~ curr_image = image_to_array(img_fname)
        # ~ curr_image2 = image_to_array(img_fname)
        # ~ curr_image  = normalize_image2(curr_image2, 0, 1)

        # And finally we preload some variables to prepare for our button
        # reading loop.

        btn = None
        # The time it took to decide on the mean luminance
        t = 0.0
        # Whether escape was pressed
        escp = False

        while (btn != "Space") & (escp != True):

            (btn, t1) = hrl.inputs.readButton()

            frm1 = hrl.graphics.newTexture(curr_image)
            frm1.draw((0, 0), (wdth, hght))
            hrl.graphics.flip(clr=True)

            if btn == "Escape":
                escp = True
                break

        if escp:
            print "Session cancelled"
            break

        print LumS, "     ", LumCD, "     ", LumCL