def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) L = normalizeVector(np.array([-0.2, 0.3, 0.7])) sfs_method = Wu08SFS(L, C0_32F, A_8U) sfs_method.run() N_32F = sfs_method.normal() fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 2 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r"Shading: $C$") plot_grid.showImage(normalToColor(N_32F, A_8U), r"Estimated Normal: $N$") showMaximize()
def setImageFile(self, image_file): self._image_file = image_file image = loadRGBA(self._image_file) self.setImage(image) self._normal = None self._depth = None self.updatedDepth.emit(self._image, self._depth)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) L = normalizeVector(np.array([-0.2, 0.3, 0.7])) sfs_method = Wu08SFS(L, C0_32F, A_8U) sfs_method.run() N_32F = sfs_method.normal() fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 2 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'Shading: $C$') plot_grid.showImage(normalToColor(N_32F, A_8U), r'Estimated Normal: $N$') showMaximize()
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) # if A_8U is None: # return C0_32F = to32F(rgb(C0_8U)) I_32F = luminance(C0_32F) Lab_32F = rgb2Lab(C0_32F) th_specular = 0.2 th_contour = 0.02 th_material = 0.1 E_32F = DoG(I_32F, sigma=2.0) contour = th_contour * np.min(E_32F) - E_32F contour *= 1.0 / np.max(contour) contour = np.clip(contour, 0.0, 1.0) specular = E_32F - th_specular * np.max(E_32F) specular *= 1.0 / np.max(specular) specular = np.clip(specular, 0.0, 1.0) material = rgb(C0_8U) # edge_mask = np.zeros(I_32F.shape, dtype=np.uint8) # edge_mask[contour > 0.0] = 1.0 # material = cv2.inpaint(material, edge_mask, 3, cv2.INPAINT_TELEA) for i in xrange(1): material = cv2.medianBlur(material, ksize=7) # material = th_material * np.max(np.abs(E_32F)) - np.abs(E_32F) # material *= 1.0 / np.max(material) # material = np.clip(material, 0.0, 1.0) # material[material > 0.0] = 1.0 E_32F[E_32F < 0.0] = 0.0 fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'$C$') #plot_grid.showImage(setAlpha(C0_32F, material), r'$Material$') plot_grid.showImage(setAlpha(material, A_8U), r'$Material$') plot_grid.showImage(setAlpha(C0_32F, contour), r'$Contour$') plot_grid.showImage(setAlpha(C0_32F, specular), r'$Specular$') showMaximize()
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) I_32F = luminance(C0_32F) N0_32F, A_8U = loadNormal( self.characterResultFile("N0_d.png", data_name="BaseDetailSepration")) Nd_32F, A_8U = loadNormal( self.characterResultFile("N_d_smooth.png", data_name="BaseDetailSepration")) Nb_32F, A_8U = loadNormal( self.characterResultFile("N_b_smooth.png", data_name="BaseDetailSepration")) W_32F = np.array(Nb_32F[:, :, 2]) W_32F = W_32F W_32F[W_32F < 0.95] = 0.0 L = lightEstimation(I_32F, N0_32F, A_8U) # L = lightEstimationByVoting(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'$C$') plot_grid.showImage(normalToColor(N0_32F, A_8U), r'$N$') plot_grid.showImage(setAlpha(C0_32F, W_32F), r'$Nd_z$') plot_grid.showImage( L_img, r'$L: [%s, %s, %s]$' % (L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def _runLayer(self, layer_file): if layer_file is None: return C0_8U = loadRGBA(layer_file) if C0_8U is None: C0_8U = loadRGB(layer_file) if C0_8U is None: return h, w = C0_8U.shape[:2] w_low = 1024 h_low = w_low * h / w # C0_8U = cv2.resize(C0_8U, (w_low, h_low)) A_8U = alpha(C0_8U) self._A_8U = A_8U C0_32F = to32F(rgb(C0_8U)) if A_8U is not None: C0_32F[A_8U < 0.9 * np.max(A_8U), :] = np.array([0, 0, 0]) self._C0_32F = C0_32F self._loadImage() self._computeBaseDetalSeparation() self._computeInitialDetailNormal() self.computeDetailNormal() self._computeLumoNormal() self.computeInitialNormal() # plt.savefig(self.characterResultFile("BumpNormal.png")) if self._N_b_smooth is not None: self.cleanCharacterResultDir() saveNormal(self.characterResultFile("N_b.png"), self._N_b, A_8U) saveNormal(self.characterResultFile("N_b_smooth.png"), self._N_b_smooth, A_8U) saveNormal(self.characterResultFile("N_d.png"), self._N_d, A_8U) saveNormal(self.characterResultFile("N_d_smooth.png"), self._N_d_smooth, A_8U) saveNormal(self.characterResultFile("N_lumo.png"), self._N_lumo, A_8U) saveNormal(self.characterResultFile("N0_b.png"), self._N0_b_32F, A_8U) saveNormal(self.characterResultFile("N0_d.png"), self._N0_d_32F, A_8U)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return if os.path.exists(self._segmentationFile()): self._stroke_sets.load(self._segmentationFile()) self._tool.setStrokeSets(self._stroke_sets) self._view.update() else: self._tool.clearStrokeSets() self._computeSegmentaiton(C0_8U)
def shapeFigure(): fig, axes = plt.subplots(figsize=(10, 8)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.1, wspace=0.1) fig.suptitle("", fontsize=font_size) num_rows = 4 num_cols = 5 plot_grid = SubplotGrid(num_rows, num_cols) for shape_file in shapeFiles(): N_8U = loadRGBA(shape_file) plot_grid.showImage(N_8U, "") file_path = os.path.join(shapeResultsDir(), "3DModels.png") fig.savefig(file_path, transparent=True)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return C0_32F = to32F(rgb(C0_8U)) I_32F = luminance(C0_32F) N0_32F, A_8U = loadNormal(self.characterResultFile("N0_d.png", data_name="BaseDetailSepration")) Nd_32F, A_8U = loadNormal(self.characterResultFile("N_d_smooth.png", data_name="BaseDetailSepration")) Nb_32F, A_8U = loadNormal(self.characterResultFile("N_b_smooth.png", data_name="BaseDetailSepration")) W_32F = np.array(Nb_32F[:, :, 2]) W_32F = W_32F W_32F[W_32F < 0.95] = 0.0 L = lightEstimation(I_32F, N0_32F, A_8U) # L = lightEstimationByVoting(I_32F, N0_32F, A_8U) L_txt = 0.01 * np.int32(100 * L) L_img = lightSphere(L) fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(C0_8U, r'$C$') plot_grid.showImage(normalToColor(N0_32F, A_8U), r'$N$') plot_grid.showImage(setAlpha(C0_32F, W_32F), r'$Nd_z$') plot_grid.showImage(L_img, r'$L: [%s, %s, %s]$' %(L_txt[0], L_txt[1], L_txt[2])) showMaximize()
def _runCharacterImp(self): print self.fullLayerFile() C0_8U = loadRGBA(self.fullLayerFile()) if C0_8U is None: return C0_32F = to32F(C0_8U) print C0_32F h, w = C0_32F.shape[:2] w_low = 512 h_low = w_low * h / w C0_32F = cv2.resize(C0_32F, (w_low, h_low)) self._normal_constraint.clear() if os.path.exists(self.characterConstraintFile()): self._normal_constraint.load(self.characterConstraintFile()) self._tool.setImage(C0_32F)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return A_32F = to32F(A_8U) C0_32F = to32F(rgb(C0_8U)) I0_32F = luminance(C0_32F) initial_normals = ["N_lumo.png", "N0_d.png"] layer_name = os.path.splitext(os.path.basename(layer_file))[0] for initial_normal in initial_normals: N0_32F, AN_8U = loadNormal(self.characterResultFile(initial_normal, data_name="BaseDetailSepration")) N_32F, L, C_32F, M = self._runSFS(C0_32F, A_8U, N0_32F, AN_8U) L_img = lightSphere(L) M_img = M.mapImage() fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.9, hspace=0.12, wspace=0.02) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(normalToColor(N0_32F, A_8U), r'Initial Normal: $N_0$') plot_grid.showImage(normalToColor(N_32F, A_8U), r'Estimated Normal: $N$') plot_grid.showImage(C0_8U, r'Shading: $C_0$') plot_grid.showImage(setAlpha(C_32F, A_32F), r'Recovered Shading: $C$') out_file_path = self.characterResultFile("ToonSFS" + initial_normal, layer_name=layer_name) plt.savefig(out_file_path) N_trim = trim(N_32F, A_8U) N0_trim = trim(N0_32F, A_8U) C0_trim = trim(C0_32F, A_8U) A_trim = trim(A_8U, A_8U) out_file_path = self.characterResultFile(initial_normal, layer_name=layer_name) saveNormal(out_file_path, N_trim, A_trim) images = self._relightingImages(N_trim, A_trim, M) initial_normal_name = os.path.splitext(initial_normal)[0] video_name = "Relighting" + initial_normal_name + ".wmv" out_file_path = self.characterResultFile(video_name, layer_name=layer_name) saveVideo(out_file_path, images) images = self._relightingOffsetImages(L, C0_trim, N0_trim, A_trim, M) video_name = "RelightingOffset" + initial_normal_name + ".wmv" out_file_path = self.characterResultFile(video_name, layer_name=layer_name) saveVideo(out_file_path, images)
def _runLayer(self, layer_file): C0_8U = loadRGBA(layer_file) if C0_8U is None: return A_8U = alpha(C0_8U) if A_8U is None: return A_32F = to32F(A_8U) C0_32F = to32F(rgb(C0_8U)) I0_32F = luminance(C0_32F) initial_normals = ["N_lumo.png", "N0_d.png"] layer_name = os.path.splitext(os.path.basename(layer_file))[0] for initial_normal in initial_normals: N0_32F, AN_8U = loadNormal( self.characterResultFile(initial_normal, data_name="BaseDetailSepration")) N_32F, L, C_32F, M = self._runSFS(C0_32F, A_8U, N0_32F, AN_8U) L_img = lightSphere(L) M_img = M.mapImage() fig, axes = plt.subplots(figsize=(11, 5)) font_size = 15 fig.subplots_adjust(left=0.02, right=0.98, top=0.9, hspace=0.12, wspace=0.02) fig.suptitle(self.name(), fontsize=font_size) num_rows = 1 num_cols = 4 plot_grid = SubplotGrid(num_rows, num_cols) plot_grid.showImage(normalToColor(N0_32F, A_8U), r'Initial Normal: $N_0$') plot_grid.showImage(normalToColor(N_32F, A_8U), r'Estimated Normal: $N$') plot_grid.showImage(C0_8U, r'Shading: $C_0$') plot_grid.showImage(setAlpha(C_32F, A_32F), r'Recovered Shading: $C$') out_file_path = self.characterResultFile("ToonSFS" + initial_normal, layer_name=layer_name) plt.savefig(out_file_path) N_trim = trim(N_32F, A_8U) N0_trim = trim(N0_32F, A_8U) C0_trim = trim(C0_32F, A_8U) A_trim = trim(A_8U, A_8U) out_file_path = self.characterResultFile(initial_normal, layer_name=layer_name) saveNormal(out_file_path, N_trim, A_trim) images = self._relightingImages(N_trim, A_trim, M) initial_normal_name = os.path.splitext(initial_normal)[0] video_name = "Relighting" + initial_normal_name + ".wmv" out_file_path = self.characterResultFile(video_name, layer_name=layer_name) saveVideo(out_file_path, images) images = self._relightingOffsetImages(L, C0_trim, N0_trim, A_trim, M) video_name = "RelightingOffset" + initial_normal_name + ".wmv" out_file_path = self.characterResultFile(video_name, layer_name=layer_name) saveVideo(out_file_path, images)