Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Articles - Page 138 of 540
597 Views
To convert a negative image to positive −Read the required image using ImageIO.read() method.Get the height and width of the image.Using nested for loops traverse through each pixel in the image.Get the pixel value using the getRGB() method.To retrieve each value from a pixel you need to right shift to the beginning position of each color i.e. 24 for alpha 16 for red etc. and perform bitwise and operation with 0Xff. This masks the variable leaving the last 8 bits and ignoring all the rest of the bits.Calculate the new red, green and blue values by subtracting them from 255.Reconstruct ... Read More
407 Views
Algorithm to convert an image to negativeGet the red green blue values of each pixelSubtract each color value from 255 and save them as new color values.Create a new pixel value from the modified colors.set the new value to the pixel.Implementation in JavaRead the required image using ImageIO.read() method.Get the height and width of the image.Using nested for loops traverse through each pixel in the image.Get the pixel value using the getRGB() method.Create a Color object bypassing the above-retrieved pixel value as parameter.Get the red, green, blue values from the color object using the getRed(), getGreen() and getBlue() methods respectively.Calculate ... Read More
871 Views
Java 9 has introduced a new feature is the creation of a REPL (Read-Evaluate-Print-Loop) called JShell. It is a command-line prompt tool to evaluate Java code without the need to write a complete program.When we can enter code or internal commands in JShell, we need to use it during the current session. When we can close JShell and log-in again, all of the code previously entered has lost. An internal command has been implemented in order to save all code entered into a file using the "/save" command./ save [file-path] / save -all [file-path] / save -history [file-path] / save -start ... Read More
4K+ Views
A pixel is the smallest element of a digital image, each pixel contains the values of alpha, red, green, blue values. The pixel value(s) is stored in a 32-bit memory space holding ARGB values (8 bits each) in the same order. Therefore, to modify the color of an image −You need to loop through each pixel in the image.Get the pixel value using the getRGB() method.Retrieve the ARGB values from the pixel value.Perform the required modifications to the RGB values.Create a new pixel value with the modified RGB values.Set the new pixel value(s) using the setRGB() method.Setting the ARGB values ... Read More
378 Views
You can compute bitwise or between two images using the bitwise_or() method of the org.opencv.core.Core class.This method accepts three Mat objects representing the source, destination and result matrices, calculates the bitwise disjunction of each element in the source matrices and stores the result in the destination matrix.ExampleIn the following Java example, we are converting an image into a binary and grayscale and calculating the bitwise disjunction of the results.import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class BitwiseORExample { public static void main(String args[]) throws Exception { //Loading the OpenCV core library ... Read More
431 Views
The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −src − A Matrix object representing source.dst − A Matrix object representing the destination.code − An integer value representing the color of the destination image.To convert a colored image to grayscale you need to pass Imgproc.COLOR_RGB2BGR as the third parameter to this method.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class ColorToGrayscale { public static void main(String args[]) throws Exception { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); ... Read More
787 Views
Using the OpenCV library you can perform image processing operations such as image filtering, geometrical image transformations, color space conversion, histograms, etc.Writing an imageWhenever you read the contents of an image using the imread() method of the Imgcodecs class the result is read into the Matrix object.You can write/save an image using the imwrite() method. This accepts two parameters namely −File − A string value representing the file path to which the result should be stored.Img − A matrix object containing the data of the image to be saved.ExampleThe following Java example reads the contents of the image cat.jpg as a ... Read More
1K+ Views
An unnamed module is a concept of the unnamed package. It is a module in which packages or classes can't be defined in any named module but exist in the jar file from classpath. If our code can try to load type from those files, the module system attempts to lookup classpath and loads it.An unnamed module read all other modules, including all of the named, built-in platform modules, and also exports all of its packages. The package in an unnamed module can be ignored, which is also defined in the named module.The unnamed module has access to:All packages exported by all other modules available in module-path.All the jars ... Read More
405 Views
Java 9 has improved Process API, and it helps to manage and control operating system processes. Before Java 9, it has been difficult to manage and control operating system processes using Java programs. Since Java 9, new classes and interfaces have added to control the operating system process through Java programs. New interfaces like ProcessHandle and ProcessHandle.Info have added, and also new methods have added to Process class.In the below example, we can traverse a process tree (children and descendant processes) of Process API.Exampleimport java.io.IOException; public class ProcessTreeTest { public static void main(String args[]) throws IOException { Runtime.getRuntime().exec("cmd"); ... Read More
838 Views
Java 9 has added improvements to Process API for getting PID of running process, getting children and/or descendants of a process, and also added a new class that helps to list out all running processes, getting information about an arbitrary process, and traversing process tree. The information returned by these methods can be a snapshot of processes running on the OS.In the below example, we can get an ID of the running process by using the pid() method of ProcessHandle.Examplepublic class ProcessHandleTest { public static void main(String args[]) { ProcessHandle processHandle = ProcessHandle.current(); System.out.println("PID of running Process: " + ... Read More