#   list_of_images = [list_of_images[0]]
  save_to = save_to_dir+cur_dir[-11:]
  while list_of_images:
    current_image = list_of_images.pop()
    image_id = os.path.split(current_image)[1].split('.')[0]
    with open(current_image, 'r') as ff:
      lbl = ff.readline().replace('\n', '').strip()
    background_image.save(save_to+'/frame_files/'+'blank.png')
    object_specs = os.path.split(glob.glob(cur_dir+'/*'+image_id+'*.png')[0])[1].split('.')
    object_id = int(object_specs[-3])
    ##create a "one_object" instance
    oo = imo.one_object(original_image_folder+image_id+'.png', original_object_map_folder+image_id+'.png', object_id)
    ##create a composition for the object
    tc = imo.boring_composition(SIDE=SIDE, locations=box_centers, radius = radius)
    ##create a montage for presenting the object
    mo = imo.montage(SIDE, background_image, tc)
    ##create the list
    mo.object_list = [oo]*tc.number_of_objects 
    ##make the pictures with objects, location cues and no labels for pcp runs
    try:
    	object_pictures = mo.show_picture(mask_margin=mask_margin)
    except:
		1/0
    ##show them for good measure
    mo.show_picture(flat=True)[0].show()
    cnt = 0
    ##add text to each pasted object frame and save
    for ii,op in enumerate(object_pictures):
      imo.put_text(op, message = lbl, position = (.5, .5), fill=box_colors[ii],size = category_cue_font_size).save(save_to+'/frame_files/'+image_file_names % (image_id,  object_id, cnt,'image'))
      copy_background = Image.open('/Users/tnaselar/Data/Presentation/single.object.boxes/Boxes2.png')
      imo.put_text(copy_background, message = lbl, position = (.5, .5), fill=box_colors[ii],size = category_cue_font_size).save(save_to+'/frame_files/'+image_file_names % (image_id,  object_id, cnt,'cue'))
  
  
def find_object_values(mask):
	'''
	object_values = find_object_values(mask)
	Find pixel values of each of the objects in an object mask
	Returns a numpy array containing the values. 
	len(object_values) = total number of objects in the mask
	'''
	from numpy import unique, array
	return unique(array(mask))


while im_ids:
  ##instantiate montage with random geometry
  obj_comp = imo.simple_composition(SIDE, 1, min_radius=min_obj_size, max_radius=max_obj_size)
  m = imo.montage(SIDE, background_image, obj_comp, mask_margin = mask_margin, object_background=background_contrast, reveal_corners = 5)
  ##loop over number of objects
  while not m.full():
    ##sample an object
    im, mask, object_id, imdx = grab_image(im_dir, im_ids)
    m.add_one_object(im, mask, object_id)
  ##print picture to file
  m.picture.save(save_to+imdx)
  m.background_picture.save(save_to+'background.'+imdx)
  labeled = imo.put_text(m.background_picture, message = labels.pop(), position = (.5, .5), size = font_size)
  labeled.save(save_to+'label.background.'+imdx)
  
  
        ##create a "one_object" instance
        oo = imo.one_object(
            original_image_folder + image_id + ".png", original_object_map_folder + image_id + ".png", object_id
        )
        ##create a "target_composition" for the object
        tc = imo.target_composition(
            target.shape[0],
            number_of_locations,
            oo,
            target,
            max_radius=max_object_radius,
            min_radius=min_object_radius,
            try_this_many=try_this_many,
        )
        ##create a montage for presenting the object
        mo = imo.montage(SIDE, imo.make_a_blank(SIDE, background_image_color, "RGB"), tc)
        ##create the list
        mo.object_list = [oo] * tc.number_of_objects
        ##make the pictures with objects, location cues and no labels for pcp runs
        object_pictures = mo.show_picture(mask_margin=mask_margin, reveal_corners=location_cue_size)
        ##show them for good measure
        mo.show_picture(flat=True)[0].show()
        cnt = 0
        for op in object_pictures:
            imo.reveal_center(op, fixation_dot_size, fill=fixation_dot_color).save(
                save_to + "/frame_files/" + image_file_names % (image_id, object_id, cnt, "image")
            )
            cnt += 1

        ##make pictures with location cues only for both the pcp and img runs
        cue_pictures = mo.show_picture(mask_margin=mask_margin, reveal_corners=location_cue_size, locations_only=True)