- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
504 Views
The convertTo() method of the org.opencv.core.Mat class accepts 4 parameters namely: mat(empty matrix), rtype(integer), alpha(integer), beta(integer), in the same order.To increase the brightness − You need to reduce the beta value from 0 towards -255(keeping alpha value 1).To decrease the brightness − You need to increase the beta value from 0 towards 255(keeping alpha value 1).To increase the contrast − You need to increase the alpha value from 1 towards 100(keeping beta value 0).To decrease the contrast − You need to decrease the alpha value from 1 to 0 (keeping beta value 0).ExampleFollowing is a JavaFX program with two slide ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
126 Views
One way to alter the brightness of an image using Java is to use the convertTo() method. This method performs the required calculations on the given matrix to alter the contrast and brightness of an image. This method accepts 4 parameters −mat − Empty matrix to hold the result with the same size and type as the source matrix.rtype − integer value specifying the type of the output matrix. If this value is negative, the type will be same as the source.alpha − Gain value, which must be greater than 0 (default value 1).beta − Bias value (default value 0).if ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
827 Views
Sharpening an image is the opposite of blur. To alter the sharpness of an image using the OpenCV library, you need to smooth/blur it using the Gaussian filter and subtract the smoothed version from the original image.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class AlteringSharpness { public static void main (String[] args) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the Image from the file String file ="D:\Image\lamma1.jpg"; Mat src = Imgcodecs.imread(file, Imgcodecs.IMREAD_COLOR); //Creating an ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
681 Views
The convertTo() method of the org.opencv.core.Mat class performs the required calculations on the given matrix to alter the contrast and brightness of an image. This method accepts 4 parameters −mat − Empty matrix to hold the result with the same size and type as the source matrix.rtype − integer value specifying the type of the output matrix. If this value is negative, the type will be the same as the source.alpha − Gain value, which must be greater than 0 (default value 1).beta − Bias value (default value 0).Altering the brightness of an image using OpenCV Java libraryAs mentioned the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
849 Views
The increasing/decreasing of brightness and contrast of an image are the operations that can be achieved by transforming the pixels of the image. this can be expressed in the form of an equation as −g(i, j) = α . f(i, j)+ βWhere, (i, j) are the positions of the pixels.α (gain) and β (bias) are the parameters of the transformation.At times the gain parameter controls the contrast of an image and the bias parameter controls the brightness of an image.The convertTo() method of the org.opencv.core.Mat class performs the required calculations on the given matrix to alter the contrast and brightness ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
5K+ Views
To compare two images −Read Both of them using the Image.IO.read() method.Get the height and width of both of them to make sure they are equal.Get the pixel values and, get the RGB values of both of the images.Get the sum of the differences between the RGB values of these two images.Calculate the percentage of the difference using the following formula −Average = difference/weight*height*3; Percentage = (Average/255)*100;Exampleimport java.awt.Color; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import java.io.File; public class ComparingImages { public static void main(String[] args) throws Exception { BufferedImage img1 = ImageIO.read(new File("D:\Images\test1.jpg")); BufferedImage img2 ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
713 Views
The flip() method of the Core class of OpenCV flips an image along the x/y axis. This method accepts −A source matrix congaing the data of the original image.An empty destination matrix to hold the data of the resultant image.A flip code to specify the direction of the image (0 –x axis, +ve – y axis, – ve both the axes).To flip an image −Load the OpenCV core native library, using the loadLibrary() method.Read the contents of the image file to a matrix using the imread() method.Create an empty matric to hold the result.Invoke the flip() method by passing the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
347 Views
Following Java example draws a watermark (“Hello”) on the given image and saves it back.Exampleimport java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class WaterMarkExample { public static void main(String[] args) throws IOException { //Reading the contents of an image File file = new File("D:\Images\test1.jpg"); BufferedImage img = ImageIO.read(file); //Creating an empty image for output int height = img.getHeight(); int width = img.getWidth(); BufferedImage res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
540 Views
To create a mirror imageRead the required image using ImageIO.read() method.Get the height and width of the image.Create an empty buffered image to store the resultUsing nested for loops traverse through each pixel in the image.Iterate the width of the image from right to left.Get the pixel value using the getRGB() method.Set the pixel values to the result image object using the setRGB() method, by replacing the new width values.Exampleimport java.io.File; import java.io.IOException; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class MirrorImage { public static void main(String args[])throws IOException { //Reading the image File file= ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
367 Views
To convert the colored image to grayscale.Get the red green blue values of each pixelGet the average of these 3 colors.Replace the RGB values with the average.Create a new pixel value from the modified colors.Set the new value to the pixel.Exampleimport java.io.File; import java.io.IOException; import java.awt.Color; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class Color2Grey { public static void main(String args[])throws IOException { //Reading the image File file= new File("D:\Images\car.jpg"); BufferedImage img = ImageIO.read(file); for (int y = 0; y < img.getHeight(); y++) { for ... Read More