def save_all_heatmaps_by_user(self):
        """
        Saves all heatmaps in image files, this method compares all heatmaps associated to this user
        and outputs images based on the minimums and maximums from all heatmaps. It also applies a logarithmic
        normalizer because of some very high values compared to others which affects scaling
        :return: None
        """
        # prepare dirs
        dir = config.WORKING_DIRECTORY + self.manager.project_name + "/users/"
        if not os.path.exists(dir):
            os.makedirs(dir)
        dir = dir + "user_" + self.user_id + "/"
        if not os.path.exists(dir):
            os.makedirs(dir)
        dir = dir + "gazemaps_image_method/"
        if not os.path.exists(dir):
            os.makedirs(dir)

        max_val = 0
        avg_val = 0
        l = 0
        # determines an average value for all the ln heatmaps
        # determines the highest value found on all the heatmaps
        for im_id in self.image_data:
            pos = self.image_data[im_id].user_positions[self.user_id]
            heatmap = np.copy(pos['heatmap'])
            heatmap = heatmap + 1
            heatmap = np.log(heatmap)
            tmp = np.max(heatmap)
            max_val = max(tmp, max_val)
            if len(heatmap[heatmap > 0]) > 0:
                avg_val = np.mean(heatmap[heatmap > 0])
                l = l + 1
            del heatmap
        if l == 0:
            gc.collect()
            return

        avg_val = avg_val / l
        # Save all heatmaps while taking to account max and avg
        for im_id in self.image_data:
            rgb_im = self.image_data[im_id].image.convert('RGB')
            rgb_im.save('converted_image.jpg')

            out = dir + im_id + "_heatmap.png"
            pos = self.image_data[im_id].user_positions[self.user_id]
            heatmap = np.copy(pos['heatmap'])
            heatmap = heatmap + 1
            heatmap = np.log(heatmap)
            heatmap[0][0] = max_val
            save_heatmap(heatmap, (self.image_data[im_id].rescaled_width,
                                   self.image_data[im_id].rescaled_height),
                         imagefile='converted_image.jpg',
                         savefilename=out,
                         alpha=0.5,
                         avg=avg_val,
                         annotations=self.image_data[im_id].ref_annotations)
            del heatmap
            os.remove('converted_image.jpg')
        gc.collect()
Beispiel #2
0
 def save_all_heatmaps_reduced(self, bar):
     rgb_im = self.image.convert('RGB')
     rgb_im.save('converted_image.jpg')
     dir = self.image_dir + "gazemap_reduced/"
     if not os.path.exists(dir):
         os.makedirs(dir)
     for u_id in self.user_positions:
         out = dir + u_id + "_heatmap.png"
         heatmap = generate_reduced_heatmap(self.user_positions[u_id],(self.rescaled_width, self.rescaled_height), self)
         save_heatmap(heatmap, (self.rescaled_width, self.rescaled_height), imagefile='converted_image.jpg',
                      savefilename=out, alpha=0.5, annotations=self.ref_annotations)
         gc.collect()
         bar.next()
     os.remove('converted_image.jpg')
Beispiel #3
0
 def save_all_heatmaps(self):
     """
     Save all heatmaps in images files, no normalization
     :return: None
     """
     rgb_im = self.image.convert('RGB')
     rgb_im.save('converted_image.jpg')
     dir = self.image_dir + "gazemaps_basic/"
     if not os.path.exists(dir):
         os.makedirs(dir)
     for u_id in self.user_positions:
         out = dir + u_id + "_heatmap.png"
         pos = self.user_positions[u_id]
         heatmap = np.copy(pos['heatmap'])
         save_heatmap(heatmap, (self.rescaled_width, self.rescaled_height), imagefile='converted_image.jpg', savefilename=out, alpha=0.5, annotations=self.ref_annotations)
         del heatmap
     gc.collect()
     os.remove('converted_image.jpg')
Beispiel #4
0
 def save_all_heatmaps_ln(self):
     """
     Saves all heatmaps in image files. It applies a logarithmic
     normalizer because of some very high values compared to others which affects scaling
     :return: None
     """
     rgb_im = self.image.convert('RGB')
     rgb_im.save('converted_image.jpg')
     dir = self.image_dir + "gazemaps_ln_method/"
     if not os.path.exists(dir):
         os.makedirs(dir)
     for u_id in self.user_positions:
         out = dir + u_id + "_heatmap.png"
         pos = self.user_positions[u_id]
         heatmap = np.copy(pos['heatmap'])
         heatmap = heatmap + 1
         heatmap = np.log10(heatmap)
         save_heatmap(heatmap, (self.rescaled_width, self.rescaled_height), imagefile='converted_image.jpg', savefilename=out, alpha=0.5, annotations=self.ref_annotations)
         del heatmap
     gc.collect()
     os.remove('converted_image.jpg')