Example #1
0
    def augmentation(self, imgs):
        s0, s1, s2, gt = imgs

        # reconstruct cosine curve
        i_0, i_45, i_90, i_135 = calc_fourPolar_from_stokes(s0, s1, s2)
        i_list = np.array([i_0, i_45, i_90, i_135])

        # add gaussian noise
        row, col, ch = s0.shape
        for inum in range(i_list.shape[0]):
            gauss = np.random.normal(0, self.sigma, (row, col, ch))
            gauss = gauss.reshape(row, col, ch)
            i_list[inum] += gauss

        # calc new stokes images
        i_0 = i_list[0]
        i_45 = i_list[1]
        i_90 = i_list[2]
        i_135 = i_list[3]

        s0, s1, s2 = calc_s0s1s2_from_fourPolar(i_0, i_45, i_90, i_135)
        s0 = np.clip(s0, 0, 1)
        s1 = np.clip(s1, -1, 1)
        s2 = np.clip(s2, -1, 1)

        s0, s1, s2 = de_normalize_s0s1s2(s0, s1, s2, self.max)
        return (s0, s1, s2, gt)
    def operation(self, s0, s1, s2):

        i_0, i_45, i_90, i_135 = pol.calc_fourPolar_from_stokes(s0, s1, s2)

        i_0 = self.averageRGB(i_0) * self.range_max
        i_45 = self.averageRGB(i_45) * self.range_max
        i_90 = self.averageRGB(i_90) * self.range_max
        i_135 = self.averageRGB(i_135) * self.range_max

        return np.array([i_0, i_45, i_90, i_135])
    def operation(self, s0, s1, s2):

        i_0, i_45, i_90, i_135 = pol.calc_fourPolar_from_stokes(s0, s1, s2)

        i_0 *= self.range_max
        i_45 *= self.range_max
        i_90 *= self.range_max
        i_135 *= self.range_max

        stokes_array = np.array([
            i_0[2, :, :], i_0[1, :, :], i_0[0, :, :], i_45[2, :, :],
            i_45[1, :, :], i_45[0, :, :], i_90[2, :, :], i_90[1, :, :],
            i_90[0, :, :], i_135[2, :, :], i_135[1, :, :], i_135[0, :, :]
        ])

        return stokes_array
 def augmentation(self, imgs):
     s0, s1, s2, gt, s0spe, s1spe, s2spe, s0dif, s1dif, s2dif = imgs
     
     """mn = np.mean(s0) * self.max
     newmn = np.random.normal(mn, mn/4)
     gain = newmn / mn
     if gain < 0:
         raise ValueError("gain should be larger than 0!")"""
     
     # random number [a, b)
     a, b = 0.5, 1.5
     gain = (b - a) * np.random.rand() + a
     
     # reconstruct cosine curve
     i_0, i_45, i_90, i_135 = calc_fourPolar_from_stokes(s0, s1, s2)
     i_0spe, i_45spe, i_90spe, i_135spe = calc_fourPolar_from_stokes(
             s0spe, s1spe, s2spe)
     i_0dif, i_45dif, i_90dif, i_135dif = calc_fourPolar_from_stokes(
             s0dif, s1dif, s2dif)
     
     # multiply gain
     i_0 *= gain
     i_45 *= gain
     i_90 *= gain
     i_135 *= gain
     
     i_0spe *= gain
     i_45spe *= gain
     i_90spe *= gain
     i_135spe *= gain
     
     i_0dif *= gain
     i_45dif *= gain
     i_90dif *= gain
     i_135dif *= gain
     
     # return back to s0s1s2
     s0 = i_0 + i_90
     s1 = i_0 - i_90
     s2 = i_45 - i_135
     
     s0spe = i_0spe + i_90spe
     s1spe = i_0spe - i_90spe
     s2spe = i_45spe - i_135spe
     
     s0dif = i_0dif + i_90dif
     s1dif = i_0dif - i_90dif
     s2dif = i_45dif - i_135dif
     
     # clipping
     s0 = np.clip(s0, 0, 1)
     s1 = np.clip(s1, -1, 1)
     s2 = np.clip(s2, -1, 1)
     
     s0spe = np.clip(s0spe, 0, 1)
     s1spe = np.clip(s1spe, -1, 1)
     s2spe = np.clip(s2spe, -1, 1)
     
     s0dif = np.clip(s0dif, 0, 1)
     s1dif = np.clip(s1dif, -1, 1)
     s2dif = np.clip(s2dif, -1, 1)
     
     # denormalize
     s0, s1, s2 = de_normalize_s0s1s2(s0, s1, s2, self.max)
     s0spe, s1spe, s2spe = de_normalize_s0s1s2(s0spe, s1spe, s2spe, self.max)
     s0dif, s1dif, s2dif = de_normalize_s0s1s2(s0dif, s1dif, s2dif, self.max)
     
     return (s0, s1, s2,
             gt,
             s0spe, s1spe, s2spe,
             s0dif, s1dif, s2dif)
Example #5
0
for gain in gains:
    data = mydataAugmentation_difSpe.DataAugmentation_difSpe_Base(
        csvpaths, 16, "gain_{}".format(str(gain)))

    for path in data.path_list:
        data.make_savedir(path)
        savepath = pathlib.Path(str(path) + "_" + data.operationName)

        csv = np.loadtxt(path.joinpath("path.csv"), delimiter=",", dtype=str)

        for i in range(csv.shape[0]):
            s0, s1, s2, gt, s0spe, s1spe, s2spe, s0dif, s1dif, s2dif = data.load_image(
                path, csv[i, :])

            i0, i45, i90, i135 = mpl.calc_fourPolar_from_stokes(s0, s1, s2)
            i0_spe, i45_spe, i90_spe, i135_spe = mpl.calc_fourPolar_from_stokes(
                s0spe, s1spe, s2spe)
            i0_dif, i45_dif, i90_dif, i135_dif = mpl.calc_fourPolar_from_stokes(
                s0dif, s1dif, s2dif)

            # multiply gain
            i0 *= gain
            i45 *= gain
            i90 *= gain
            i135 *= gain

            i0_spe *= gain
            i45_spe *= gain
            i90_spe *= gain
            i135_spe *= gain