Java के माध्यम से पृष्ठभूमि को DICOM में बदलें
सर्वर-साइड API का उपयोग करके DICOM फ़ाइलों में पृष्ठभूमि बदलने के लिए अपने स्वयं के Java ऐप्स बनाएं।
Java का उपयोग करके DICOM फ़ाइलों में पृष्ठभूमि कैसे बदलें
अक्सर, आदर्श छवि प्राप्त करने के लिए पृष्ठभूमि बदलने की आवश्यकता होती है। वांछित DICOM प्रारूप छवि प्रभाव प्राप्त करने के लिए, अग्रभूमि वस्तुओं को शेष चित्र से अलग किया जाना चाहिए। यदि पृष्ठभूमि एक समान हो तो स्वचालित वस्तु का पता लगाना संभव है। यदि फोटो की पृष्ठभूमि असमान है या वस्तु को अलग करना चुनौतीपूर्ण है, तो छवि को पहले से चिह्नित करने की सिफारिश की जाती है। इसमें फोटो के भीतर आयताकार क्षेत्रों की पहचान करना शामिल है जहां इच्छित वस्तुएं रहती हैं और उनके प्रकार निर्दिष्ट करना शामिल है। यह क्लाउड एपीआई की ऑब्जेक्ट पहचान सुविधा के माध्यम से मैन्युअल रूप से या स्वचालित रूप से किया जा सकता है। ऑब्जेक्ट चयन और मूल पृष्ठभूमि को हटाने के बाद, एक नई पृष्ठभूमि लागू की जा सकती है या पारदर्शिता लागू की जा सकती है। DICOM फ़ाइलों में पृष्ठभूमि बदलने के लिए, हम इसका उपयोग करेंगे Aspose.Imaging for Java API जो एक सुविधा संपन्न, शक्तिशाली और जावा प्लेटफॉर्म के लिए छवि हेरफेर और रूपांतरण एपीआई का उपयोग करने में आसान है। आप इसका नवीनतम संस्करण सीधे Maven से डाउनलोड कर सकते हैं और इसे अपने मावेन में इंस्टॉल कर सकते हैं -आधारित परियोजना pom.xml में निम्नलिखित विन्यास जोड़कर।
रिपॉजिटरी
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
निर्भरता
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
Java के माध्यम से DICOMs में पृष्ठभूमि बदलने के चरण
अपने स्वयं के वातावरण में निम्नलिखित वर्कफ़्लो को आज़माने के लिए आपको aspose-imaging-version-jdk16.jar की आवश्यकता होगी।
- DICOM फ़ाइलें Image.load विधि से लोड करें
- पृष्ठभूमि बदलें;
- Aspose द्वारा समर्थित डिस्क में छवि सहेजें। इमेजिंग प्रारूप
सिस्टम आवश्यकताएं
Aspose.Imaging for Java सभी प्रमुख ऑपरेटिंग सिस्टम पर समर्थित है। बस सुनिश्चित करें कि आपके पास निम्नलिखित पूर्वापेक्षाएँ हैं।
- JDK 1.6 या उच्चतर स्थापित है।
DICOM छवियों में पृष्ठभूमि बदलें - Java
import com.aspose.imaging.*; | |
import com.aspose.imaging.fileformats.png.PngColorType; | |
import com.aspose.imaging.imageoptions.PngOptions; | |
import com.aspose.imaging.masking.IMaskingSession; | |
import com.aspose.imaging.masking.ImageMasking; | |
import com.aspose.imaging.masking.options.*; | |
import com.aspose.imaging.masking.result.MaskingResult; | |
import com.aspose.imaging.sources.FileCreateSource; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.function.Consumer; | |
//Most common example to demonstrate background change/remove tool | |
removeBackgroundGenericExample(); | |
// Folder that contains images to process | |
static final String templatesFolder = "c:\\Data\\"; | |
public static void removeBackgroundProcessingWithManualRectangles() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", | |
"wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach(new Consumer<String>() | |
{ | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background_manual_rectangles." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setFeatheringRadius(2); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
AutoMaskingArgs maskingArgs = new AutoMaskingArgs(); | |
maskingArgs.setObjectsRectangles(new Rectangle[] | |
{ | |
// girl's bound box | |
new Rectangle(87, 47, 123, 308), | |
// boy's bound box | |
new Rectangle(180, 24, 126, 224) | |
}); | |
maskingOptions.setArgs(maskingArgs); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
IMaskingSession maskingSession = new ImageMasking(image) | |
.createSession(maskingOptions); | |
try | |
{ | |
// first run of segmentation | |
maskingSession.decompose().dispose(); | |
AutoMaskingArgs argsWithUserMarkers = new AutoMaskingArgs(); | |
argsWithUserMarkers.setObjectsPoints(new Point[][] | |
{ | |
// background markers | |
null, | |
// foreground markers | |
new UserMarker() | |
// boy's head | |
.addPoint(218, 48, 10) | |
// girl's head | |
.addPoint(399, 66, 10) | |
// girs's body | |
.addPoint(158, 141, 10) | |
.addPoint(158, 209, 20) | |
.addPoint(115, 225, 5) | |
.getPoints() | |
}); | |
try (MaskingResult maskingResult = maskingSession | |
.improveDecomposition(argsWithUserMarkers)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
finally | |
{ | |
maskingSession.dispose(); | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundAutoProcessingWithAssumedObjects() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", | |
"wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder | |
+ "remove_background_auto_assumed_objects." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
final LinkedList<AssumedObjectData> assumedObjects = new LinkedList<>(); | |
// girl's bound box | |
assumedObjects.add( | |
new AssumedObjectData(DetectedObjectType.Human, | |
new Rectangle(87, 47, 123, 308))); | |
// boy's bound box | |
assumedObjects.add( | |
new AssumedObjectData(DetectedObjectType.Human, | |
new Rectangle(180, 24, 126, 224))); | |
maskingOptions.setAssumedObjects(assumedObjects); | |
maskingOptions.setCalculateDefaultStrokes(true); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundAutoProcessing() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", | |
"wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background_auto." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundGenericExample() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", | |
"wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setCalculateDefaultStrokes(true); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
private static String rasterizeVectorImage(String formatExt, String inputFile) | |
{ | |
String outputFile = templatesFolder + "rasterized."+ formatExt + ".png"; | |
try (Image image = Image.load(inputFile)) | |
{ | |
image.save(outputFile, new PngOptions()); | |
} | |
return outputFile; | |
} | |
class UserMarker | |
{ | |
private final List<Point> list = new LinkedList<>(); | |
public UserMarker addPoint(int left, int top, int radius) | |
{ | |
for (int y = top - radius; y <= top + radius; y++) | |
{ | |
for (int x = left - radius; x <= left + radius; x++) | |
{ | |
this.list.add(new Point(x, y)); | |
} | |
} | |
return this; | |
} | |
public Point[] getPoints() | |
{ | |
return this.list.toArray(new Point[0]); | |
} | |
} |
Aspose.Imaging for Java API . के बारे में
Aspose.Imaging API अनुप्रयोगों के भीतर छवियों (फ़ोटो) को बनाने, संशोधित करने, आकर्षित करने या परिवर्तित करने के लिए एक छवि प्रसंस्करण समाधान है। यह प्रदान करता है: क्रॉस-प्लेटफ़ॉर्म छवि प्रसंस्करण, जिसमें विभिन्न छवि प्रारूपों (समान बहु-पृष्ठ या बहु-फ़्रेम छवि प्रसंस्करण सहित) के बीच रूपांतरण शामिल हैं, लेकिन इन्हीं तक सीमित नहीं है, ड्राइंग जैसे संशोधन, ग्राफिक प्राइमेटिव के साथ काम करना, परिवर्तन (आकार बदलना, फसल करना, फ्लिप करना और घुमाना) , बिनाराइज़ेशन, ग्रेस्केल, एडजस्ट), उन्नत छवि हेरफेर सुविधाएँ (फ़िल्टरिंग, डिथरिंग, मास्किंग, डेस्क्यूइंग), और मेमोरी ऑप्टिमाइज़ेशन रणनीतियाँ। यह एक स्टैंडअलोन लाइब्रेरी है और इमेज ऑपरेशंस के लिए किसी सॉफ्टवेयर पर निर्भर नहीं है। परियोजनाओं के भीतर देशी एपीआई के साथ आसानी से उच्च-प्रदर्शन छवि रूपांतरण सुविधाएँ जोड़ सकते हैं। ये 100% निजी ऑन-प्रिमाइसेस एपीआई हैं और छवियों को आपके सर्वर पर संसाधित किया जाता है।ऑनलाइन ऐप के द्वारा DICOMs में पृष्ठभूमि बदलें
हमारी लाइव डेमो वेबसाइट पर जाकर DICOM दस्तावेज़ों में पृष्ठभूमि बदलें। लाइव डेमो के निम्नलिखित लाभ हैं
DICOM क्या है DICOM फाइल का प्रारूप
DICOM चिकित्सा में डिजिटल इमेजिंग और संचार के लिए संक्षिप्त है और चिकित्सा सूचना विज्ञान के क्षेत्र से संबंधित है। DICOM फ़ाइल स्वरूप परिभाषा और एक नेटवर्क संचार प्रोटोकॉल का संयोजन है। DICOM .DCM एक्सटेंशन का उपयोग करता है। .DCM दो अलग-अलग स्वरूपों में मौजूद है अर्थात स्वरूप 1.x और स्वरूप 2.x। DCM प्रारूप 1.x आगे सामान्य और विस्तारित दो संस्करणों में उपलब्ध है। DICOM का उपयोग विभिन्न विक्रेताओं से चिकित्सा इमेजिंग उपकरणों जैसे प्रिंटर, सर्वर, स्कैनर आदि के एकीकरण के लिए किया जाता है और इसमें विशिष्टता के लिए प्रत्येक रोगी का पहचान डेटा भी होता है। DICOM फ़ाइलें दो पक्षों के बीच साझा की जा सकती हैं यदि वे DICOM प्रारूप में छवि डेटा प्राप्त करने में सक्षम हैं। DICOM का संचार भाग अनुप्रयोग परत प्रोटोकॉल है और संस्थाओं के बीच संचार के लिए TCP/IP का उपयोग करता है। DICOM की वेब सेवाओं के लिए HTTP और HTTPS प्रोटोकॉल का उपयोग किया जाता है। वेब सेवाओं द्वारा समर्थित संस्करण 1.0, 1.1, 2 या बाद के संस्करण हैं।
अधिक पढ़ेंअन्य समर्थित परिवर्तन पृष्ठभूमि प्रारूप
Java का उपयोग करके, कोई भी व्यक्ति विभिन्न स्वरूपों में पृष्ठभूमि को आसानी से बदल सकता है, जिसमें शामिल हैं।