def rm_txt(self): imgpath = state.now_image() maskpath = state.now_mask() if imgpath is None: return None self.saveMask.emit(maskpath) # save edited mask image = io.load(imgpath, io.IMAGE) mask =(io.load(maskpath, io.MASK) if Path(maskpath).exists() else io.mask2segmap(self.gen_mask())) inpainted = core.inpainted(image, mask) io.save(state.now_image(), inpainted) self.update_gui()
def segmentPage(self,imgPath,outputInpaintedPath,outputTextOnlyPath): self.resize(imgPath) #because of sickzil has poor quality on high resolution image #process sickzil fileName=os.path.basename(imgPath) oriImage = imgio.load(imgPath, imgio.IMAGE) #ori image maskImage = imgio.mask2segmap(self.imgpath2mask(imgPath)) #mask image inpaintedImage = core.inpainted(oriImage, maskImage) #notext image textOnlyImage= cv2.bitwise_and(oriImage,maskImage) #text only image textOnlyImage[maskImage==0] = 255 imgio.save(outputInpaintedPath+fileName, inpaintedImage) imgio.save(outputTextOnlyPath+fileName, textOnlyImage)
def gen_mask_all(self): ''' Generate NEW mask of all image. NOTE: All previously saved masks will be overwritten. ''' if state.now_image() is None: return None masks = fp.map(imgpath2mask, state.img_paths) for path,mask in tqdm(zip(state.mask_paths, masks), total=len(state.img_paths), desc='Generate Masks'): io.save(path, mask) self.update_gui() return masks
def segmentImage(self, downloadFileList, inpaintedFolder, textOnlyFolder): # image segmentation for i, imgPath in enumerate(tqdm(downloadFileList)): print("image path: ", imgPath) fileName = os.path.basename(imgPath) oriImage = imgio.load(imgPath, imgio.IMAGE) #ori image # imgpath2mask(imgPath) # mask image is a black image with features (text) being white maskImage = imgio.mask2segmap( self.imgpath2mask(imgPath)) #mask image # remove all the text from the original image # this is used later on to write new translated texts on it. inpaintedImage = core.inpainted(oriImage, maskImage) #notext image # convert all the texts from white to black color (white-white => white, else black) # we need to convert to black color text for what ? # for easier reading and easier for oct algo to detect text textOnlyImage = cv2.bitwise_and(oriImage, maskImage) #text only image #if i==0: #cv2.imshow("text_only_img", textOnlyImage) textOnlyImage[maskImage == 0] = 255 imgio.save(inpaintedFolder + fileName, inpaintedImage) imgio.save(textOnlyFolder + fileName, textOnlyImage)
def rm_txt(imgpath, maskpath, outputpath): if imgpath is None: return None image = io.load(imgpath, io.IMAGE) mask = io.load(maskpath, io.MASK) inpainted = core.inpainted(image, mask) io.save(outputpath, inpainted)
def genmask(imgpath, outputpath): mask = imgpath2mask(imgpath) io.save(outputpath, mask)
def genmask(imgpath): mask = imgpath2mask(imgpath) io.save("./mask.png", mask)