├── img ├── 1.png └── 2.png ├── requirements.txt ├── README.md └── main.py /img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemanth5666/BgRemover/HEAD/img/1.png -------------------------------------------------------------------------------- /img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemanth5666/BgRemover/HEAD/img/2.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow==10.2.0 2 | plyer==2.1.0 3 | PyQt5==5.15.10 4 | PyQt5_sip==12.13.0 5 | QtPy==2.0.1 6 | rembg==2.0.55 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Features 2 | 3 | Background Removal: Utilizes the rembg library to remove backgrounds from images. 4 | Drag and Drop Interface: Allows users to conveniently upload images by dragging and dropping them onto the interface. 5 | Efficient Processing: Utilizes multi-threading to process multiple images simultaneously, enhancing efficiency. 6 | Save Processed Images: Provides the option to save the processed images to the local system. 7 | 8 | Requirements 9 | 10 | Python 3.x 11 | rembg library (Install using pip install rembg) 12 | Other dependencies (specified in requirements.txt) 13 | ![2](https://github.com/hemanth5666/Bgremover/assets/95521874/21c0cb2b-355e-4736-a6c5-abfbd2637726) 14 | ![1](https://github.com/hemanth5666/Bgremover/assets/95521874/2ae80976-bb6d-486a-869c-a0e15663a767) 15 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton, QFileDialog 4 | from PyQt5.QtGui import QPixmap 5 | from PyQt5.QtCore import Qt 6 | from rembg import remove 7 | from PIL import Image 8 | import concurrent.futures 9 | 10 | class DragDropWindow(QMainWindow): 11 | def __init__(self): 12 | super().__init__() 13 | self.setWindowTitle("Drag and Drop Image Processor") 14 | self.setGeometry(100, 100, 600, 400) 15 | 16 | self.central_widget = QWidget(self) 17 | self.setCentralWidget(self.central_widget) 18 | 19 | self.layout = QVBoxLayout(self.central_widget) 20 | 21 | self.label = QLabel("Drag and drop images here", self) 22 | self.label.setAlignment(Qt.AlignCenter) 23 | self.label.setStyleSheet("border: 2px dashed #aaa;") 24 | self.layout.addWidget(self.label) 25 | 26 | self.save_button = QPushButton("Save Images", self) 27 | self.save_button.clicked.connect(self.save_images) 28 | self.layout.addWidget(self.save_button) 29 | 30 | self.setAcceptDrops(True) 31 | 32 | def dragEnterEvent(self, event): 33 | if event.mimeData().hasUrls(): 34 | event.accept() 35 | else: 36 | event.ignore() 37 | 38 | def dropEvent(self, event): 39 | file_paths = [url.toLocalFile() for url in event.mimeData().urls() if url.toLocalFile().endswith('.jpg') or url.toLocalFile().endswith('.png')] 40 | if file_paths: 41 | self.process_images(file_paths) 42 | 43 | def process_images(self, file_paths): 44 | with concurrent.futures.ThreadPoolExecutor() as executor: 45 | futures = [] 46 | for file_path in file_paths: 47 | futures.append(executor.submit(self.process_image, file_path)) 48 | for future in concurrent.futures.as_completed(futures): 49 | future.result() 50 | 51 | def process_image(self, file_path): 52 | try: 53 | # Load image lazily 54 | with Image.open(file_path) as input_image: 55 | # Resize image 56 | input_image = input_image.resize((800, 600)) # Resize to a smaller resolution 57 | output_image = remove(input_image, alpha=True, alpha_matting=True) 58 | output_folder = "output_images" 59 | if not os.path.exists(output_folder): 60 | os.makedirs(output_folder) 61 | output_path = os.path.join(output_folder, os.path.basename(file_path).split('.')[0] + '.png') 62 | output_image.save(output_path) 63 | self.show_image(output_path) 64 | except Exception as e: 65 | print("Error processing image:", e) 66 | 67 | def show_image(self, image_path): 68 | pixmap = QPixmap(image_path) 69 | if not pixmap.isNull(): 70 | self.label.setPixmap(pixmap.scaled(self.label.size(), Qt.KeepAspectRatio)) 71 | else: 72 | print("Failed to load image") 73 | 74 | def save_images(self): 75 | output_folder = "output_images" 76 | if not os.path.exists(output_folder): 77 | os.makedirs(output_folder) 78 | for filename in os.listdir(output_folder): 79 | if filename.endswith('.png'): 80 | os.remove(os.path.join(output_folder, filename)) 81 | self.label.clear() 82 | 83 | if __name__ == "__main__": 84 | app = QApplication(sys.argv) 85 | window = DragDropWindow() 86 | window.show() 87 | sys.exit(app.exec_()) 88 | --------------------------------------------------------------------------------