The jpgimage is decoded in JPEG decoding. The decoded data is divided into three colors: RGB. The three colors (in hexadecimal format) are stored in red in three files. dat, green. dat, blue. dat; use MATLAB to restore the three-color data into an image.
Here, only the red color is processed, and the other two colors are processed in a similar way.
Here we decode a jpg image of 1080*1920.
The red. dat file stores hexadecimal data.
For example, only 12 data records are listed here, with a total of 1080x1920 data records.
MATLAB sourceProgramAs follows:
RGB
1 Clear;
2 RGB = imread ( ' Blank.jpg ' );
3 Red = zeros ( 1080 ,1920 );
4 A = textread ( ' Red. dat ' , ' % S ' ) ' ;
5 B = hex2dec ();
6 C = uint8 (B );
7 For I = 1 : 1080
8 For J = 1 : 1920
9 M = 1920 * (I- 1 ) + J;
10 Red (I, j) = C (m );
11 End
12 End
13
14 RGB (:,:, 1 ) = Red;
15 RGB (:,:, 2 ) = 0 ;
16 RGB (:,:, 3 ) = 0 ;
17 JPEG = imread ( ' Picture.jpg ' );
18 Subplot ( 1 , 2 , 1 ), Imshow (JPEG );
19 Subplot ( 1 , 2 , 2 ), Imshow (RGB );
Row 3: blance.jpg is an empty 2nd * 1080 image.
Row 3rd: creates a two-dimensional array red to save the R value.
Row 4th: Read the data in the hexadecimal red. dat file and put it in.
Row 3: Convert hexadecimal to hexadecimal.
Row 7-12: The read data is placed in the two-dimensional array red.
Row 3: Set the red weight.
Row 3: Set the green component. Set this parameter to 0;
Row 3: Set the blue component. Set this parameter to 0;
Row 3: Read the original image.
Line 18-19: displays the original image and decoded images with only the red weight.
Running result:
The left side is the original image, and the right side is the decoded image containing only the red weight.