Ejemplo n.º 1
0
 def _in_sample_df(df, threshold):
     ceiled_df = df.applymap(
         replace_if_condition(lambda x: x < threshold, 0))
     ceiled_df = ceiled_df.applymap(replace_if_condition(
         lambda x: x > 0, 1))
     ceiled_df = ceiled_df.applymap(lambda x: 1 - x)
     return ceiled_df
Ejemplo n.º 2
0
 def _save_in_sample_convex_hull(self, out_path, overwrite=False):
     """
     To retrieve pixels that are in the sample, we proceed as following:
     1. Mark every pixel under a certain threshold as part of the sample (above for elt 1, under for elt 2, 3, 4)
     2. Get the convex envelop of the sample pixels
     3. Save it in a file
     :return: if overwritten
     """
     if not overwrite and os.path.isfile(out_path):
         return False
     # Reverse elt 1 where the sample is brighter than the background
     # Change each element so that its smallest value is 0
     df1 = self[1].df.applymap(lambda x: self[1].max - x)
     df2 = self[2].df.applymap(lambda x: x - self[2].min)
     df3 = self[3].df.applymap(lambda x: x - self[3].min)
     df4 = self[4].df.applymap(lambda x: x - self[4].min)
     # Find the sample zone according to each diagonal element
     ceiled1 = self._in_sample_df(df1, self[1].max * 0.85)
     ceiled2 = self._in_sample_df(df2, self[2].max * 0.4)
     ceiled3 = self._in_sample_df(df3, self[3].max * 0.4)
     ceiled4 = self._in_sample_df(df4, self[4].max * 0.4)
     # Keep the sample zone common to all diagonal elements
     in_sample = ceiled1.add(ceiled2).add(ceiled3).add(ceiled4).applymap(
         replace_if_condition(lambda x: x < 4, 0, 1))
     # Get the convex envelop of the sample elements
     hull = self._find_convex_hull(in_sample)
     self._save_convex_hull(in_sample, hull, out_path)
     return True
Ejemplo n.º 3
0
 def _save_in_sample_convex_hull(self, out_path, overwrite=False):
     """
     To retrieve pixels that are in the sample, we proceed as following:
     1. Mark every pixel under a certain threshold as part of the sample (above for elt 1, under for elt 2, 3, 4)
     2. Get the convex envelop of the sample pixels
     3. Save it in a file
     :return: if overwritten
     """
     if not overwrite and os.path.isfile(out_path):
         return False
     # Reverse elt 1 where the sample is brighter than the background
     # Change each element so that its smallest value is 0
     df1 = self[1].df.applymap(lambda x: self[1].max - x)
     df2 = self[2].df.applymap(lambda x: x - self[2].min)
     df3 = self[3].df.applymap(lambda x: x - self[3].min)
     df4 = self[4].df.applymap(lambda x: x - self[4].min)
     # Find the sample zone according to each diagonal element
     ceiled1 = self._in_sample_df(df1, self[1].max * 0.85)
     ceiled2 = self._in_sample_df(df2, self[2].max * 0.4)
     ceiled3 = self._in_sample_df(df3, self[3].max * 0.4)
     ceiled4 = self._in_sample_df(df4, self[4].max * 0.4)
     # Keep the sample zone common to all diagonal elements
     in_sample = ceiled1.add(ceiled2).add(ceiled3).add(ceiled4).applymap(replace_if_condition(lambda x: x < 4, 0, 1))
     # Get the convex envelop of the sample elements
     hull = self._find_convex_hull(in_sample)
     self._save_convex_hull(in_sample, hull, out_path)
     return True
Ejemplo n.º 4
0
 def _in_sample_df(df, threshold):
     ceiled_df = df.applymap(replace_if_condition(lambda x: x < threshold, 0))
     ceiled_df = ceiled_df.applymap(replace_if_condition(lambda x: x > 0, 1))
     ceiled_df = ceiled_df.applymap(lambda x: 1 - x)
     return ceiled_df