ICO छवियाँ पृष्ठभूमि हटाने के लिए Python का उपयोग करें
सर्वर API के माध्यम से ICO छवियों और फ़ोटो का बैकग्राउंड हटाने के लिए Python ऐप्स बनाएं
Python के साथ ICO छवियों और फ़ोटो की पृष्ठभूमि कैसे हटाएं
किसी छवि या फोटो से पृष्ठभूमि हटाने के लिए प्रमुख वस्तुओं की सटीक पहचान की आवश्यकता होती है। ICO छवियों के लिए, ऑब्जेक्ट परिभाषा के लिए विभिन्न विधियाँ उपलब्ध हैं। सीधे परिदृश्यों में, स्वचालित दृष्टिकोण समान पृष्ठभूमि वाली छवियों को कुशलतापूर्वक संभालता है। फिर भी, जब कई आकृतियों या पृष्ठभूमि के साथ विलीन होने वाली वस्तुओं वाली तस्वीरों से निपटते हैं, तो प्रारंभिक वस्तु पदनाम का संचालन करने की सिफारिश की जाती है। इसमें आयताकार क्षेत्रों को मैन्युअल रूप से रेखांकित करना और हाइलाइट किए जाने वाले ऑब्जेक्ट प्रकारों को निर्दिष्ट करना शामिल है। स्वचालित ऑब्जेक्ट आवंटन के अधिक जटिल मामलों में, क्लाउड एपीआई एक विकल्प के रूप में खड़ा है। यह क्लाउड-आधारित एप्लिकेशन एक तस्वीर के भीतर वस्तुओं की पहचान करता है और पृष्ठभूमि को खत्म करने के लिए परिणामी आकृतियों को नियोजित करता है। पृष्ठभूमि हटाने के बाद, शेष वस्तुओं के किनारों को बढ़ाने से समग्र छवि गुणवत्ता में उल्लेखनीय वृद्धि हो सकती है। ICO फ़ाइलों में पृष्ठभूमि हटाने के लिए, इसका उपयोग करने का सुझाव दिया गया है Aspose.Imaging for Python via .NET एपीआई जो कि पायथन प्लेटफॉर्म के लिए एक सुविधा संपन्न, शक्तिशाली और उपयोग में आसान छवि हेरफेर और रूपांतरण एपीआई है। आप इसे अपने सिस्टम कमांड से निम्नलिखित कमांड का उपयोग करके इंस्टॉल कर सकते हैं।
द सिस्टम कमांड लाइन
>> pip install aspose-imaging-python-net
Python के माध्यम से ICOs से पृष्ठभूमि हटाने के चरण
आपको aspose-imaging-python-net की जरूरत है ताकि आप अपने खुद के माहौल में नीचे दिए गए वर्कफ़्लो को आज़मा सकें।
- लोड ICO छवि के साथ फ़ाइलें। लोड विधि
- पृष्ठभूमि निकालें;
- Aspose द्वारा समर्थित डिस्क में छवि सहेजें। इमेजिंग प्रारूप
सिस्टम आवश्यकताएं
Aspose.Imaging for Python सभी प्रमुख ऑपरेटिंग सिस्टम पर समर्थित है। बस सुनिश्चित करें कि आपके पास निम्नलिखित पूर्वापेक्षाएँ हैं।
- माइक्रोसॉफ्ट विंडोज/लिनक्स .NET कोर रनटाइम के साथ।
- पायथन और PyPi पैकेज मैनेजर।
ICO इमेज में बैकग्राउंड हटाएं - Python
from aspose.imaging import Image, RasterImage, Point, Rectangle, Color | |
from aspose.imaging.fileformats.png import PngColorType | |
from aspose.imaging.imageoptions import PngOptions | |
from aspose.imaging.masking import * | |
from aspose.imaging.masking.options import * | |
from aspose.imaging.masking.result import * | |
from aspose.imaging.sources import FileCreateSource | |
from aspose.pycore import as_of | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
def remove_background_processing_with_manual_rectangles(): | |
raster_formats = [ | |
"jpg", | |
"png", | |
"bmp", | |
"apng", | |
"dicom", | |
"jp2", | |
"j2k", | |
"tga", | |
"webp", | |
"tif", | |
"gif", | |
"ico" | |
] | |
vector_formats = [ | |
"svg", | |
"otg", | |
"odg", | |
"wmf", | |
"emf", | |
"wmz", | |
"emz", | |
"cmx", | |
"cdr" | |
] | |
all_formats: list = [] | |
all_formats.extend(raster_formats) | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"couple.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format = format_ext in vector_formats | |
# Need to rasterize vector formats before background remove | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, f"remove_background_manual_rectangles.{format_ext}.png") | |
print(f"Processing {format_ext}") | |
with as_of(Image.load(input_file), RasterImage) as image: | |
obj_init3 = AutoMaskingArgs() | |
obj_init3.objects_rectangles = [Rectangle(87, 47, 123, 308), Rectangle(180, 24, 126, 224)] | |
obj_init4 = PngOptions() | |
obj_init4.color_type = PngColorType.TRUECOLOR_WITH_ALPHA | |
obj_init4.source = FileCreateSource(output_file, False) | |
obj_init5 = AutoMaskingGraphCutOptions() | |
obj_init5.feathering_radius = 2 | |
obj_init5.method = SegmentationMethod.GRAPH_CUT | |
obj_init5.args = obj_init3 | |
obj_init5.export_options = obj_init4 | |
masking_options = obj_init5 | |
with ImageMasking(image).create_session(masking_options) as masking_session: | |
# first run of segmentation | |
with masking_session.decompose() as _: | |
pass | |
args_with_user_markers = AutoMaskingArgs() | |
obj_init_list = [ | |
# background markers | |
None, | |
# foreground markers | |
UserMarker() | |
# boy's head | |
.add_point(218, 48, 10) | |
# girl's head | |
.add_point(399, 66, 10) | |
# girs's body | |
.add_point(158, 141, 10) | |
.add_point(158, 209, 20) | |
.add_point(115, 225, 5) | |
.get_points()] | |
args_with_user_markers.objects_points = obj_init_list | |
with masking_session.improve_decomposition(args_with_user_markers) as masking_result: | |
with masking_result[1].get_image() as result_image: | |
result_image.save() | |
if delete_output: | |
os.remove(output_file) | |
# Remove rasterized vector image | |
if is_vector_format and delete_output: | |
os.remove(input_file) | |
def remove_background_auto_processing_with_assumed_objects(): | |
raster_formats = [ | |
"jpg", | |
"png", | |
"bmp", | |
"apng", | |
"dicom", | |
"jp2", | |
"j2k", | |
"tga", | |
"webp", | |
"tif", | |
"gif"] | |
vector_formats = [ | |
"svg", | |
"otg", | |
"odg", | |
"eps", | |
"wmf", | |
"emf", | |
"wmz", | |
"emz", | |
"cmx", | |
"cdr"] | |
all_formats = [] | |
all_formats.extend(raster_formats) | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"couple.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format = format_ext in vector_formats | |
# Need to rasterize vector formats before background remove | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, | |
f"remove_background_auto_assumed_objects.{format_ext}.png") | |
print(f"Processing {format_ext}") | |
with as_of(Image.load(input_file), RasterImage) as image: | |
obj_init9 = list() | |
obj_init9.append(AssumedObjectData(DetectedObjectType.HUMAN, Rectangle(87, 47, 123, 308))) | |
obj_init9.append(AssumedObjectData(DetectedObjectType.HUMAN, Rectangle(180, 24, 126, 224))) | |
obj_init10 = PngOptions() | |
obj_init10.color_type = PngColorType.TRUECOLOR_WITH_ALPHA | |
obj_init10.source = FileCreateSource(output_file, False) | |
obj_init11 = AutoMaskingGraphCutOptions() | |
obj_init11.assumed_objects = obj_init9 | |
obj_init11.calculate_default_strokes = True | |
obj_init11.feathering_radius = 1 | |
obj_init11.method = SegmentationMethod.GRAPH_CUT | |
obj_init11.export_options = obj_init10 | |
obj_init11.background_replacement_color = Color.green | |
masking_options = obj_init11 | |
with ImageMasking(image).decompose(masking_options) as masking_result: | |
with masking_result[1].get_image() as result_image: | |
result_image.save() | |
# Remove rasterized vector image | |
if is_vector_format and delete_output: | |
os.remove(input_file) | |
if delete_output: | |
os.remove(output_file) | |
def remove_background_auto_processing(): | |
raster_formats = [ | |
"jpg", | |
"png", | |
"bmp", | |
"apng", | |
"dicom", | |
"jp2", | |
"j2k", | |
"tga", | |
"webp", | |
"tif", | |
"gif"] | |
vector_formats = [ | |
"svg", | |
"otg", | |
"odg", | |
"eps", | |
"wmf", | |
"emf", | |
"wmz", | |
"emz", | |
"cmx", | |
"cdr"] | |
all_formats: list = [] | |
all_formats.extend(raster_formats) | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"couple.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format = format_ext in vector_formats | |
# Need to rasterize vector formats before background remove | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, f"remove_background_auto.{format_ext}.png") | |
print(f"Processing {format_ext}") | |
with as_of(Image.load(input_file), RasterImage) as image: | |
obj_init14 = PngOptions() | |
obj_init14.color_type = PngColorType.TRUECOLOR_WITH_ALPHA | |
obj_init14.source = FileCreateSource(output_file, False) | |
obj_init15 = AutoMaskingGraphCutOptions() | |
obj_init15.feathering_radius = 1 | |
obj_init15.method = SegmentationMethod.GRAPH_CUT | |
obj_init15.export_options = obj_init14 | |
obj_init15.background_replacement_color = Color.green | |
masking_options = obj_init15 | |
with ImageMasking(image).decompose(masking_options) as masking_result: | |
with masking_result[1].get_image() as result_image: | |
result_image.save() | |
# Remove rasterized vector image | |
if is_vector_format and delete_output: | |
os.remove(input_file) | |
if delete_output: | |
os.remove(output_file) | |
def remove_background_generic_example(): | |
raster_formats = [ | |
"jpg", | |
"png", | |
"bmp", | |
"apng", | |
"dicom", | |
"jp2", | |
"j2k", | |
"tga", | |
"webp", | |
"tif", | |
"gif"] | |
vector_formats = [ | |
"svg", | |
"otg", | |
"odg", | |
"wmf", | |
"emf", | |
"wmz", | |
"emz", | |
"cmx", | |
"cdr"] | |
all_formats: list = [] | |
all_formats.extend(raster_formats) | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"couple.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format: bool = format_ext in vector_formats | |
# Need to rasterize vector formats before background remove | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, f"remove_background.{format_ext}.png") | |
print(f"Processing {format_ext}") | |
with as_of(Image.load(input_file), RasterImage) as image: | |
obj_init18 = PngOptions() | |
obj_init18.color_type = PngColorType.TRUECOLOR_WITH_ALPHA | |
obj_init18.source = FileCreateSource(output_file, False) | |
obj_init19 = AutoMaskingGraphCutOptions() | |
obj_init19.calculate_default_strokes = True | |
obj_init19.feathering_radius = 1 | |
obj_init19.method = SegmentationMethod.GRAPH_CUT | |
obj_init19.export_options = obj_init18 | |
obj_init19.background_replacement_color = Color.green | |
masking_options = obj_init19 | |
with ImageMasking(image).decompose(masking_options) as masking_result: | |
with masking_result[1].get_image() as result_image: | |
result_image.save() | |
# Remove rasterized vector image | |
if is_vector_format and delete_output: | |
os.remove(input_file) | |
if delete_output: | |
os.remove(output_file) | |
def rasterize_vector_image(format_ext, input_file): | |
output_file: str = os.path.join(templates_folder, f"rasterized.{format_ext}.png") | |
with Image.load(input_file) as image: | |
image.save(output_file, PngOptions()) | |
return output_file | |
class UserMarker: | |
def __init__(self): | |
self._list: list = [] | |
def add_point(self, left, top, radius): | |
for y in range(top - radius, top + radius + 1): | |
for x in range(left - radius, left + radius + 1): | |
self._list.append(Point(x, y)) | |
return self | |
def get_points(self): | |
return self._list | |
# Run examples | |
remove_background_auto_processing_with_assumed_objects() | |
remove_background_processing_with_manual_rectangles() | |
remove_background_auto_processing() | |
remove_background_generic_example() |
Aspose.Imaging for Python API . के बारे में
Aspose.Imaging API अनुप्रयोगों के भीतर छवियों (फ़ोटो) को बनाने, संशोधित करने, आकर्षित करने या परिवर्तित करने के लिए एक छवि प्रसंस्करण समाधान है। यह प्रदान करता है: क्रॉस-प्लेटफ़ॉर्म छवि प्रसंस्करण, जिसमें विभिन्न छवि प्रारूपों (समान बहु-पृष्ठ या बहु-फ़्रेम छवि प्रसंस्करण सहित) के बीच रूपांतरण शामिल हैं, लेकिन इन्हीं तक सीमित नहीं है, ड्राइंग जैसे संशोधन, ग्राफिक प्राइमेटिव के साथ काम करना, परिवर्तन (आकार बदलना, फसल करना, फ्लिप करना और घुमाना) , बिनाराइज़ेशन, ग्रेस्केल, एडजस्ट), उन्नत छवि हेरफेर सुविधाएँ (फ़िल्टरिंग, डिथरिंग, मास्किंग, डेस्क्यूइंग), और मेमोरी ऑप्टिमाइज़ेशन रणनीतियाँ। यह एक स्टैंडअलोन लाइब्रेरी है और इमेज ऑपरेशंस के लिए किसी सॉफ्टवेयर पर निर्भर नहीं है। परियोजनाओं के भीतर देशी एपीआई के साथ आसानी से उच्च-प्रदर्शन छवि रूपांतरण सुविधाएँ जोड़ सकते हैं। ये 100% निजी ऑन-प्रिमाइसेस एपीआई हैं और छवियों को आपके सर्वर पर संसाधित किया जाता है।ऑनलाइन ऐप के द्वारा ICOs में पृष्ठभूमि हटाएं
हमारी लाइव डेमो वेबसाइट पर जाकर ICO दस्तावेज़ों की पृष्ठभूमि हटाएं। लाइव डेमो के निम्नलिखित लाभ हैं
ICO क्या है ICO फाइल का प्रारूप
ICO फ़ाइल स्वरूप Microsoft Windows में कंप्यूटर आइकन के लिए एक छवि फ़ाइल स्वरूप है। ICO फाइलों में एक या एक से अधिक छोटी छवियां कई आकारों और रंग गहराई में होती हैं, जैसे कि उन्हें उचित रूप से बढ़ाया जा सकता है। विंडोज़ में, सभी निष्पादन योग्य जो उपयोगकर्ता को एक आइकन प्रदर्शित करते हैं, डेस्कटॉप पर, स्टार्ट मेनू में, या विंडोज एक्सप्लोरर में, आईसीओ प्रारूप में आइकन ले जाना चाहिए।
अधिक पढ़ेंअन्य समर्थित पृष्ठभूमि प्रारूप निकालें
Python का उपयोग करके, कोई भी व्यक्ति विभिन्न प्रारूपों से पृष्ठभूमि को आसानी से हटा सकता है, जिसमें शामिल हैं।