[MATLAB Image Processing] learning notes: Reading hexadecimal RGB documents into color pictures

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.