Exemplo n.º 1
0
    def _get_lens_max(self, start_mic, axis=0):

        cur_mic = start_mic
        lens_max = 1  # start with 1 to account for upper left centroid
        odd = self.estimate_odd(start_mic, axis)

        # check if column of upper left is complete
        while cur_mic[axis] < self._lower_r[axis] + self._pitch[axis] / 2:
            # get adjacent MIC
            found_center = find_centroid(self._centroids, cur_mic, self._pitch,
                                         axis, self._pattern, odd)
            odd = not odd
            if len(found_center) != 2:
                if len(found_center) > 2:
                    # average of found centroids
                    found_center = np.mean(found_center.reshape(-1, 2), axis=0)
                else:
                    if cur_mic[axis] > (self._bbox[axis] -
                                        self._pitch[axis] / 2):
                        break
                    else:
                        odd = self.estimate_odd(start_mic, axis)
                        start_mic = find_centroid(self._centroids, start_mic,
                                                  self._pitch, not axis,
                                                  self._pattern, not odd)
                        found_center = start_mic
                        lens_max = 0
            lens_max += 1
            cur_mic = found_center

        return lens_max, cur_mic, start_mic
Exemplo n.º 2
0
 def estimate_odd(self, cur_mic, axis):
     return find_centroid(self._centroids,
                          cur_mic,
                          self._pitch,
                          axis,
                          'hex',
                          odd=False).size == 0
Exemplo n.º 3
0
    def _calc_pattern(self, pitch):
        """ This function determines whether the geometric arrangement of micro lenses is rectangular or hexagonal.

        :param pitch: scalar of type int or float representing the spacing between micro image centers
        :return: pattern, e.g. 'hex' or 'rec'
        """

        # pick arbitrary micro image center in middle of centroid list
        point = self._centroids[int(len(self._centroids) / 2)]

        diff_vertical = []
        pattern_list = ['rec', 'hex']

        for pattern in pattern_list:
            k = 1 if pattern == 'rec' else np.sqrt(3) / 2
            adj_vertical = find_centroid(self._centroids,
                                         point, [k * pitch, pitch],
                                         axis=0,
                                         pattern=pattern)
            if list(adj_vertical):
                diff_vertical.append(
                    abs(k * pitch - abs(adj_vertical[0] - point[0])))
            else:
                diff_vertical.append(float('inf'))

        # store detected pattern type
        self._pattern = pattern_list[np.array(diff_vertical).argmin()]

        return self._pattern
Exemplo n.º 4
0
    def _get_lens_max(self, start_mic, axis=0):

        lens_max = 0
        cur_mic = start_mic
        odd = self.estimate_odd(start_mic, axis)

        # check if column of upper left is complete
        while cur_mic[axis] < self._bounding_box[axis]:
            # get adjacent MIC
            found_center = find_centroid(self._centroids, cur_mic, self._pitch,
                                         axis, self._pattern, odd)
            odd = not odd
            lens_max += 1
            if len(found_center) != 2:
                if len(found_center) > 2:
                    found_center = np.mean(found_center.reshape(
                        -1, 2), axis=0)  # average over found centroids
                else:
                    if cur_mic[axis] > (self._bounding_box[axis] -
                                        1.5 * self._pitch[axis]):
                        break
                    else:
                        # look into other vertical hex direction (if applicable)
                        found_center = find_centroid(self._centroids, cur_mic,
                                                     self._pitch, axis,
                                                     self._pattern, odd)
                        if len(found_center) != 2:
                            if len(found_center) > 2:
                                found_center = np.mean(
                                    found_center.reshape(-1, 2),
                                    axis=0)  # average over found centroids
                            else:
                                # row/column of previous starting centroid incomplete: thus find new starting centroid
                                odd = self.estimate_odd(start_mic, axis)
                                start_mic = find_centroid(
                                    self._centroids, start_mic, self._pitch,
                                    not axis, self._pattern, not odd)
                                found_center = start_mic
                        else:
                            start_mic = found_center
                        lens_max = 0
            cur_mic = found_center

        return lens_max, cur_mic, start_mic
Exemplo n.º 5
0
    def _calc_pattern(self, pitch):

        point = self._centroids[int(len(self._centroids)/2)]
        diff_vertical = []
        pattern_list = ['rec', 'hex']

        for pattern in pattern_list:
            k = 1 if pattern == 'rec' else np.sqrt(3) / 2
            adj_vertical = find_centroid(self._centroids, point, [k*pitch, pitch], axis=0, pattern=pattern)
            if list(adj_vertical):
                diff_vertical.append(abs(k*pitch - abs(adj_vertical[0] - point[0])))
            else:
                diff_vertical.append(float('inf'))

        self._pattern = pattern_list[np.array(diff_vertical).argmin()]

        return True
Exemplo n.º 6
0
 def estimate_odd(self, cur_mic, axis):
     return True if find_centroid(self._centroids, cur_mic, self._pitch,
                                  axis, 'hex', False).size == 0 else False
Exemplo n.º 7
0
    def _assign_mic_idx(self):

        # reorder MIC list by neighbour relationship
        last_neighbor = self._upper_l
        self._mic_list = []
        self._mic_list.append([last_neighbor[0], last_neighbor[1], 0, 0])
        j = 0
        odd = self.estimate_odd(self._upper_l, axis=0)

        # print status
        self.sta.status_msg('Sort micro image centers',
                            self.cfg.params[self.cfg.opt_prnt])

        # jump to the next row
        for ly in range(self._lens_y_max):
            # find all centers in one row
            for lx in range(self._lens_x_max - 1):
                # get adjacent MIC
                found_center = find_centroid(self._centroids, last_neighbor,
                                             self._pitch, 1, 'rec', None)
                # retrieve missing MIC
                if len(found_center) != 2:
                    if len(found_center) > 2:
                        found_center = np.mean(
                            found_center.reshape(-1, 2),
                            axis=0)  # average over found centroids
                    else:
                        found_center = self._mic_list[j][:2] + np.array(
                            [0, self._pitch[1]])
                j += 1
                self._mic_list.append(
                    [found_center[0], found_center[1], ly, lx + 1])
                last_neighbor = found_center
            # find most-left center of next row
            if ly < self._lens_y_max - 1:
                # get adjacent MIC
                found_center = find_centroid(self._centroids, self._upper_l,
                                             self._pitch, 0, self._pattern,
                                             odd)
                # retrieve missing MIC
                if len(found_center) != 2:
                    if len(found_center) > 2:
                        found_center = np.mean(
                            found_center.reshape(-1, 2),
                            axis=0)  # average over found centroids
                    else:
                        if self._pattern == 'rec':
                            found_center = self._upper_l + np.array(
                                [self._pitch[0], 0])
                        elif self._pattern == 'hex':
                            if odd:
                                found_center = self._upper_l + np.array(
                                    [self._pitch[0], +self._pitch[1] / 2])
                            else:
                                found_center = self._upper_l + np.array(
                                    [self._pitch[0], -self._pitch[1] / 2])
                elif len(found_center) > 2:
                    found_center = found_center[:2]
                j += 1
                self._mic_list.append(
                    [found_center[0], found_center[1], ly + 1, 0])
                last_neighbor = found_center
                self._upper_l = found_center
                odd = not odd

            # check interrupt status
            if self.sta.interrupt:
                return False

            # print progress status on console
            self.sta.progress((ly + 1) / self._lens_y_max * 100,
                              self.cfg.params[self.cfg.opt_prnt])

        return True
Exemplo n.º 8
0
    def _assign_mic_idx(self):

        # reorder MIC list by neighbour relationship
        last_neighbor = self._upper_l
        self._mic_list = []
        self._mic_list.append([last_neighbor[0], last_neighbor[1], 0, 0])
        j = 0
        odd = self.estimate_odd(self._upper_l, axis=0)
        row_len_odd = True

        # print status
        self.sta.status_msg('Sort micro image centers',
                            self.cfg.params[self.cfg.opt_prnt])

        # jump to the next row
        for ly in range(self._lens_y_max):
            # find all centers in one row
            for lx in range(
                    self._lens_x_max - 1
            ):  # -1 to account for first row center which is already found
                # get adjacent MIC
                found_center = find_centroid(self._centroids, last_neighbor,
                                             self._pitch, 1, 'rec', None)
                # retrieve single MIC
                if len(found_center) != 2:
                    if len(found_center) > 2:
                        # average of found centroids
                        found_center = np.mean(found_center.reshape(-1, 2),
                                               axis=0)
                    else:
                        # skip when looking for last MIC with unequal row length
                        if lx == self._lens_x_max - 1 and (
                                row_len_odd or self._pattern == 'rec'):
                            break
                        # create missing centroid
                        found_center = self._mic_list[j][:2] + np.array(
                            [0, self._pitch[1]])
                j += 1
                self._mic_list.append(
                    [found_center[0], found_center[1], ly, lx + 1])
                last_neighbor = found_center
            # find most-left center of next row
            if ly < self._lens_y_max - 1:
                # get adjacent MIC
                found_center = find_centroid(self._centroids, self._upper_l,
                                             self._pitch, 0, self._pattern,
                                             odd)
                # retrieve single MIC
                if len(found_center) != 2:
                    if len(found_center) > 2:
                        # average of found centroids
                        found_center = np.mean(found_center.reshape(-1, 2),
                                               axis=0)
                    else:
                        # create missing centroid (considering MLA packing)
                        if self._pattern == 'rec':
                            found_center = self._upper_l + np.array(
                                [self._pitch[0], 0])
                        elif self._pattern == 'hex':
                            if odd:
                                found_center = self._upper_l + np.array(
                                    [self._pitch[0], +self._pitch[1] / 2])
                            else:
                                found_center = self._upper_l + np.array(
                                    [self._pitch[0], -self._pitch[1] / 2])
                j += 1
                self._mic_list.append(
                    [found_center[0], found_center[1], ly + 1, 0])
                last_neighbor = found_center
                self._upper_l = found_center
                odd = not odd

            # check interrupt status
            if self.sta.interrupt:
                return False

            # print progress status on console
            self.sta.progress((ly + 1) / self._lens_y_max * 100,
                              self.cfg.params[self.cfg.opt_prnt])

        return True