- Example: A website could improve its technical SEO by ensuring it has an XML sitemap, uses proper schema markup to enhance search results, and addresses any crawl errors found in Google Search Console to ensure all pages are indexed.
Author: saqibkhan
-
Technical SEO:
-
Backlink Building:
- Example: A travel website might create valuable content like a detailed “Travel Itinerary for Italy” and reach out to travel bloggers and industry sites to link back to this resource, thereby improving its authority and search engine ranking.
-
Local SEO:
- Example: A dental clinic in Los Angeles could optimize its Google My Business listing with accurate contact information, business hours, and local keywords like “dentist near downtown Los Angeles.” Encouraging satisfied patients to leave positive reviews would also help.
-
Content Creation:
- Example: A tech blog might publish a comprehensive guide on “The Ultimate Guide to 5G Technology,” covering everything from what 5G is to how it compares with 4G, with in-depth information and visuals to rank well for related search queries.
-
Keyword Optimization
- Example: A website for a local bakery could target keywords like “best cupcakes in [City]” and “gluten-free bakery [City]” to attract local customers searching for those specific products and services.
-
Enhancing Image Sharpness
In this chapter we learn to increase the sharpness of an image using Gaussian filter.
First we use OpenCV function GaussianBlur. It can be found under Imgproc package. Its syntax is given below −
Imgproc.GaussianBlur(source, destination, new Size(0,0), sigmaX);The parameters are described briefly −
Sr.No. Parameter & Description 1 sourceIt is source image. 2 destinationIt is destination image. 3 SizeIt is Gaussian kernel size. 4 sigmaXIt is Gaussian kernel standard deviation in X direction. Further, we use OpenCV function addWeighted to apply image watermark to image. It can be found under Core package. Its syntax is given below −
Core.addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst);The parameters of this function are described below −
Sr.No. Parameter & Description 1 src1It is first input array. 2 alphaIt is weight of the first array elements. 3 src2It is second input array of the same size and channel number as src1. 4 BetaIt is weight of the second array elements. 5 gammaIt is scalar added to each sum. 6 dstIt is output array that has the same size and number of channels as the input arrays. Apart from the GaussianBlur method, there are other methods provided by the Imgproc class. They are described briefly −
Sr.No. Method & Description 1 cvtColor(Mat src, Mat dst, int code, int dstCn)It converts an image from one color space to another. 2 dilate(Mat src, Mat dst, Mat kernel)It dilates an image by using a specific structuring element. 3 equalizeHist(Mat src, Mat dst)It equalizes the histogram of a grayscale image. 4 filter2D(Mat src, Mat dst, int depth, Mat kernel, Point anchor, double delta)It convolves an image with the kernel. 5 GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX)It blurs an image using a Gaussian filter. 6 integral(Mat src, Mat sum)It calculates the integral of an image. Example
The following example demonstrates the use of Imgproc and Core class to apply sharpening to an image −
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; public class Main { public static void main( String[] args ) {
} }try{ System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Highgui.imread("digital_image_processing.jpg", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(),source.cols(),source.type()); Imgproc.GaussianBlur(source, destination, new Size(0,0), 10); Core.addWeighted(source, 1.5, destination, -0.5, 0, destination); Highgui.imwrite("sharp.jpg", destination); } catch (Exception e) { }Output
When you execute the given code, the following output is seen −
Original Image

Sharped Image

-
Enhancing Image Contrast
In this chapter learn how to enhance the contrast of an image using histogram equalization.
We use the OpenCV function equalizeHist() method. It can be found under Imgproc package. Its syntax is given below −
Imgproc.equalizeHist(source, destination);The parameters are described below −
Sr.No. Parameter & Description 1 SourceIt is 8-bit single channel source image. 2 DestinationIt is the destination image. Apart from the equalizeHist() method, there are other methods provided by the Imgproc class. They are described briefly −
Sr.No. Method & Description 1 cvtColor(Mat src, Mat dst, int code, int dstCn)It converts an image from one color space to another. 2 dilate(Mat src, Mat dst, Mat kernel)It dilates an image by using a specific structuring element. 3 equalizeHist(Mat src, Mat dst)It equalizes the histogram of a grayscale image. 4 filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta)It convolves an image with the kernel. 5 GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX)It blurs an image using a Gaussian filter. 6 integral(Mat src, Mat sum)It calculates the integral of an image. Example
The following example demonstrates the use of Imgproc class to enhance contrast of an image −
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; public class Main { static int width; static int height; static double alpha = 2; static double beta = 50; public static void main( String[] args ) {
} }try { System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Highgui.imread("grayscale.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE); Mat destination = new Mat(source.rows(),source.cols(),source.type()); Imgproc.equalizeHist(source, destination); Highgui.imwrite("contrast.jpg", destination); } catch (Exception e) { System.out.println("error: " + e.getMessage()); }Output
When you execute the given code, the following output is seen −
Original Image

Enhanced Contrast Image

-
GrayScale Conversion
In order to convert a color image to Grayscale image, you need to read pixels or data of the image using File and ImageIO objects, and store the image in BufferedImage object. Its syntax is given below −
File input = new File("digital_image_processing.jpg"); BufferedImage image = ImageIO.read(input);Further, get the pixel value using method getRGB() and perform GrayScale() method on it. The method getRGB() takes row and column index as parameter.
Color c = new Color(image.getRGB(j, i)); int red = (c.getRed() * 0.299); int green =(c.getGreen() * 0.587); int blue = (c.getBlue() *0.114);Apart from these three methods, there are other methods available in the Color class as described briefly −
Sr.No. Method & Description 1 brighter()It creates a new Color that is a brighter version of this Color. 2 darker()It creates a new Color that is a darker version of this Color. 3 getAlpha()It returns the alpha component in the range 0-255. 4 getHSBColor(float h, float s, float b)It creates a Color object based on the specified values for the HSB color model. 5 HSBtoRGB(float hue, float saturation, float brightness)It converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model. 6 toString()It returns a string representation of this Color. The last step is to add all these three values and set it again to the corresponding pixel value. Its syntax is given below −
int sum = red+green+blue; Color newColor = new Color(sum,sum,sum); image.setRGB(j,i,newColor.getRGB());Example
The following example demonstrates the use of Java BufferedImage class that converts an image to Grayscale −
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.JFrame; public class GrayScale { BufferedImage image; int width; int height; public GrayScale() {
} static public void main(String args[]) throws Exception {try { File input = new File("digital_image_processing.jpg"); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); for(int i=0; i<height; i++) { for(int j=0; j<width; j++) { Color c = new Color(image.getRGB(j, i)); int red = (int)(c.getRed() * 0.299); int green = (int)(c.getGreen() * 0.587); int blue = (int)(c.getBlue() *0.114); Color newColor = new Color(red+green+blue, red+green+blue,red+green+blue); image.setRGB(j,i,newColor.getRGB()); } } File ouptut = new File("grayscale.jpg"); ImageIO.write(image, "jpg", ouptut); } catch (Exception e) {}
} }GrayScale obj = new GrayScale();Output
When you execute the given example, it converts the image digital_image_processing.jpg to its equivalent Grayscale image and write it on hard disk with the name grayscale.jpg.
Original Image

Grayscale Image

-
Image Pixels
An image contains a two dimensional array of pixels. It is actually the value of those pixels that make up an image. Usually an image could be color or grayscale.
In Java, the BufferedImage class is used to handle images. You need to call getRGB() method of the BufferedImage class to get the value of the pixel.
Getting Pixel Value
The pixel value can be received using the following syntax−
Color c = new Color(image.getRGB(j, i));Getting RGB Values
The method getRGB() takes the row and column index as a parameter and returns the appropriate pixel. In case of color image, it returns three values which are (Red, Green, Blue). They can be get as follows−
c.getRed(); c.getGreen(); c.getBlue();Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Getting Width and Height of Image
The height and width of the image can be get by calling the getWidth() and getHeight() methods of the BufferedImage class. Its syntax is given below−
int width = image.getWidth(); int height = image.getHeight();Apart from these methods, there are other methods supported in the BufferedImage class. They are described briefly−
Sr.No. Method & Description 1 copyData(WritableRaster outRaster)It computes an arbitrary rectangular region of the BufferedImage and copies it into a specified WritableRaster. 2 getColorModel()It returns ColorModel of an image. 3 getData()It returns the image as one large tile. 4 getData(Rectangle rect)It computes and returns an arbitrary region of the BufferedImage. 5 getGraphics()This method returns a Graphics2D, but is here for backwards compatibility. 6 getHeight()It returns the height of the BufferedImage. 7 getMinX()It returns the minimum x coordinate of this BufferedImage. 8 getMinY()It returns the minimum y coordinate of this BufferedImage. 9 getRGB(int x, int y)It returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. 10 getType()It returns the image type. Example
The following example demonstrates the use of java BufferedImage class that displays pixels of an image of size (100 x 100)−
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.JFrame; class Pixel { BufferedImage image; int width; int height; public Pixel() {try { File input = new File("blackandwhite.jpg"); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); int count = 0; for(int i=0; i<height; i++) { for(int j=0; j<width; j++) { count++; Color c = new Color(image.getRGB(j, i)); System.out.println("S.No: " + count + " Red: " + c.getRed() +" Green: " + c.getGreen() + " Blue: " + c.getBlue()); } }
} static public void main(String args[]) throws Exception {} catch (Exception e) {}
} }Pixel obj = new Pixel();Output
When you execute the above example, it would print the pixels of the following image −
Original Image

Pixels Output
If you scroll down the ouput, the following pattern is seen−
-
Downloading & Uploading Images
In this chapter we are going to see how you can download an image from internet, perform some image processing techniques on the image, and then again upload the processed image to a server.
Downloading an Image
In order to download an image from a website, we use java class named URL, which can be found under java.net package. Its syntax is given below −
String website = "http://tutorialspoint.com"; URL url = new URL(website);Apart from the above method, there are other methods available in class URL as described briefly −
Sr.No. Method & Description 1 public String getPath()It returns the path of the URL. 2 public String getQuery()It returns the query part of the URL. 3 public String getAuthority()It returns the authority of the URL. 4 public int getPort()It returns the port of the URL. 5 public int getDefaultPort()It returns the default port for the protocol of the URL. 6 public String getProtocol()It returns the protocol of the URL. 7 public String getHost()It returns the host of the URL. Example
The following example demonstrates the use of java URL class to download an image from the internet −
import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; public class Download { public static void main(String[] args) throws Exception {
} }try{ String fileName = "digital_image_processing.jpg"; String website = "http://tutorialspoint.com/java_dip/images/"+fileName; System.out.println("Downloading File From: " + website); URL url = new URL(website); InputStream inputStream = url.openStream(); OutputStream outputStream = new FileOutputStream(fileName); byte[] buffer = new byte[2048]; int length = 0; while ((length = inputStream.read(buffer)) != -1) { System.out.println("Buffer Read of length: " + length); outputStream.write(buffer, 0, length); } inputStream.close(); outputStream.close(); } catch(Exception e) { System.out.println("Exception: " + e.getMessage()); }Output
When you execute the given above, the following output is seen.
It would download the following image from the server.
Uploading an Image
Let us see how to upload an image to a webserver. We convert a BufferedImage to byte array in order to send it to server.
We use Java class ByteArrayOutputStream, which can be found under java.io package. Its syntax is given below −
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos);In order to convert the image to byte array, we use toByteArray() method of ByteArrayOutputStream class. Its syntax is given below −
byte[] bytes = baos.toByteArray();Apart from the above method, there are other methods available in the ByteArrayOutputStream class as described briefly −
Sr.No. Method & Description 1 public void reset()This method resets the number of valid bytes of the byte array output stream to zero, so that all the accumulated output in the stream is discarded. 2 public byte[] toByteArray()This method creates a newly allocated Byte array. Its size would be the current size of the output stream and the contents of the buffer will be copied into it. It returns the current contents of the output stream as a byte array. 3 public String toString()Converts the buffer content into a string. Translation will be done according to the default character encoding. It returns the String translated from the buffer’s content. 4 public void write(int w)It writes the specified array to the output stream. 5 public void write(byte []b, int of, int len)It writes len number of bytes starting from offset off to the stream. 6 public void writeTo(OutputStream outSt)It writes the entire content of this Stream to the specified stream argument. Example
The following example demonstrates ByteArrayOutputStream to upload an image to the server −
Client Code
import javax.swing.*; import java.net.*; import java.awt.image.*; import javax.imageio.*; import java.io.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Client{ public static void main(String args[]) throws Exception{Socket soc; BufferedImage img = null; soc=new Socket("localhost",4000); System.out.println("Client is running. "); try { System.out.println("Reading image from disk. "); img = ImageIO.read(new File("digital_image_processing.jpg")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(img, "jpg", baos); baos.flush(); byte[] bytes = baos.toByteArray(); baos.close(); System.out.println("Sending image to server. "); OutputStream out = soc.getOutputStream(); DataOutputStream dos = new DataOutputStream(out); dos.writeInt(bytes.length); dos.write(bytes, 0, bytes.length); System.out.println("Image sent to server. ");
} }dos.close(); out.close(); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); soc.close(); } soc.close();Server Code
import java.net.*; import java.io.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; class Server { public static void main(String args[]) throws Exception{ServerSocket server=null; Socket socket; server = new ServerSocket(4000); System.out.println("Server Waiting for image");socket = server.accept(); System.out.println("Client connected."); InputStream in = socket.getInputStream(); DataInputStream dis = new DataInputStream(in);int len = dis.readInt(); System.out.println("Image Size: " + len/1024 + "KB"); byte[] data = new byte[len]; dis.readFully(data); dis.close(); in.close();InputStream ian = new ByteArrayInputStream(data); BufferedImage bImage = ImageIO.read(ian);
} }JFrame f = new JFrame("Server"); ImageIcon icon = new ImageIcon(bImage); JLabel l = new JLabel(); l.setIcon(icon); f.add(l); f.pack(); f.setVisible(true);Output
Client Side Output
When you execute the client code, the following output appears on client side −
Server Side Output
When you execute the server code, the following ouptut appears on server side −
After receiving the image, the server displays the image as shown below −