Extract bit planes from an Image in Matlab

A Fundamental image processing method used to examine and visualize the various levels of information contained in a picture is extracting bit planes from the image in MATLAB. The binary values of pixel intensities at particular bit positions, from the most significant bit (MSB) to the least significant bit (LSB), are represented by bit planes. Numerous applications, such as image analysis, compression, and watermarking, can benefit from this procedure.

  • To extract bit planes from a picture in MATLAB, the image must first be divided into separate binary bit planes, each corresponding to a particular intensity level in the image.
  • The least significant bit (LSB) plane contains the lowest-order bits, which contribute the least to the overall intensity of the image. In contrast, the highest-order bits are found in the most significant bit (MSB) plane.

Here's a simple explanation and a step-by-step manual:

Read and Load the Image: Before you can extract bit planes from an image, it must first be read and loaded. Imread can be used to accomplish this.

Convert the Image to Grayscale (if necessary): To simplify the bit plane extraction procedure, you may want to change your input image from color to grayscale if it is currently in color.

Extract Bit Planes:

Bitwise operations and a loop that iterates over each bit location from the most significant bit (MSB) to the least significant bit (LSB) are used to extract the individual bit planes from the grayscale image. The bitget function can be used for this.

The bit plane (i-th bit) is extracted from the grayscale image in this loop using bitget and stored in the bitPlanes array.

Display or Save the Bit Planes:

You have the option to either display or save the extracted bit planes as individual images. Here, we'll use the imshow function to display them.

With the help of this code, a figure with subplots that each show an extracted bit plane is produced. To ensure proper scaling, the imshow function is used with an empty [] range.

Bit Planes as Images (Optional): Store the You can use the write function inside the loop to store the bit planes as individual picture files.

Each bit plane is saved using this code as a PNG image with the bit position included in the filename.

  • The bit planes of the input image have been successfully recovered and viewed in MATLAB. With the MSB carrying the most important information and the LSB containing the least important information, each bit plane will expose varying levels of visual detail.

IMPLEMENTATION:

OUTPUT:

Extract bit planes from an Image in Matlab

Clear the Output Screen (clc): This line makes sure that the output is clean and clear by clearing the MATLAB command window.

Examine the input picture: The imread function is used by the code to read a file with the name "download.jpg." Either a color or grayscale image can be used as the input. If necessary, convert the image to grayscale.

  • This determines whether the image is in color (three channels) or grayscale (one channel).
  • To make the bit plane extraction procedure simpler, it converts any color images to grayscale using the rgb2gray function.

Store image data as a double-precision array: The image data is transformed.

Store Image Data as a Double: To enable numerical operations, the image data is transformed into a double-precision array cd.

Initialize an Array for Bit Planes: The extracted bit planes are stored in the array bitPlanes, which is initialized. It has the same dimensions as the input image and an extra dimension of 8 for storing each bit plane (from the first to the eighth).

First through eighth-bit planes: Extract All: The first through eighth bits are iterated in a loop. Divide the image data by 2 raised to the (i-1)-th power inside the loop to extract each bit plane using the mod and floor functions. The bitPlanes array is used to store the outcome.

Make a displayable subplot layout: Layout is determined by the code. Visualize how each bit plane contributed to the original image and how they worked together to recreate it. It's a helpful method for figuring out how the binary encoding of picture data affects image quality.

Implementation:

OUTPUT:

Extract bit planes from an Image in Matlab
  • Clear the Command Window in MATLAB for a clean output display by typing clc (clear the output screen).
  • 'Yourimg.jpg' is the image that the application reads from the input. It would help if you substituted the exact filename and directory of the image you wish to process for "download.jpg."
  • Store Image Data as a Double: To enable numerical operations, the image data is transformed into a double-precision array cd.
  • Initialize a Bit Planes Array: The extracted bit planes are initialized in an array called bitPlanes. It has measurements.
  • Extract All: The first through eighth bits are iterated through in a loop. Divide the image data by 2 raised to the (i-1)-th power inside the loop to extract each bit plane using the mod and floor functions. The bitPlanes array is used to store the outcome.
  • Display the Original Image: Last but not least, the imshow function is used to display the original image with the label "Original Image."

Implementation:

OUTPUT:

Extract bit planes from an Image in Matlab

The offered MATLAB software is made to separate and show a picture's bit planes before recombining them to show the original image.

A list of the program's features is provided below:

Clear the Output Screen (clc;): Creates a clean output by clearing the MATLAB command window.' Download.jpg' should be replaced with the path of your image when reading an input image.

  • To process an image in color, it is converted to grayscale.'Download.jpg' should be replaced with the path of your image when reading an input image.
  • To process an image in color, it is converted to grayscale.

Convert the Input Image to Double: For bit manipulation, convert the input image to a double-precision array.

Initialize an Array for Bit Planes: Creates a bitPlanes array with dimensions that match the input image and a data type of uint8 to hold the individual bit planes.

Extract All Bit Planes (from 1st to 8th): Using the bitget function, a loop extracts each bit plane and stores it in the bitPlanes array.

Create Subplots for Display: The software constructs a figure, sets up subplots to display each eight-bit plane separately, and arranges the main plot.






Latest Courses