CN112215775B - BMP picture restoration method and device - Google Patents

BMP picture restoration method and device Download PDF

Info

Publication number
CN112215775B
CN112215775B CN202011126750.5A CN202011126750A CN112215775B CN 112215775 B CN112215775 B CN 112215775B CN 202011126750 A CN202011126750 A CN 202011126750A CN 112215775 B CN112215775 B CN 112215775B
Authority
CN
China
Prior art keywords
data
bmp
damaged
bmp picture
judging whether
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011126750.5A
Other languages
Chinese (zh)
Other versions
CN112215775A (en
Inventor
杜辉阳
唐军
沈长达
黄志炜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xiamen Meiya Pico Information Co Ltd
Original Assignee
Xiamen Meiya Pico Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiamen Meiya Pico Information Co Ltd filed Critical Xiamen Meiya Pico Information Co Ltd
Priority to CN202011126750.5A priority Critical patent/CN112215775B/en
Publication of CN112215775A publication Critical patent/CN112215775A/en
Application granted granted Critical
Publication of CN112215775B publication Critical patent/CN112215775B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/77Retouching; Inpainting; Scratch removal

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)
  • Facsimile Image Signal Circuits (AREA)

Abstract

The invention relates to a BMP picture repairing method and a device, wherein the method comprises the following steps: s1, obtaining information of a damaged BMP picture file from a reference BMP picture file; s2, self-judging to obtain data of a first reference row; s3, repairing line by line; s4, loss data filling; and S5, generating a BMP picture file. The method expands the picture restoration mode and creates a precedent of RGB (red, green and blue) bare stream pixel data restoration, is a supplement to the picture and even video restoration algorithm, and has great innovation and practical significance.

Description

BMP picture restoration method and device
Technical Field
The invention relates to a picture file repairing technology, in particular to a BMP picture repairing method and device based on a color gradient principle.
Background
The BMP is a standard image file format on windows operating systems, and is supported by various windows applications. A relatively common image file format has been developed today. The application is very wide in the field of digital images, for example, the BMP format can be used for mobile phone photographing, image transmission in chatting, screenshot and the like. The picture in BMP format is often damaged due to unexpected situations in daily use, such as loss of heartbeat packets in network transmission, device failure, file system damage, and the like.
Since the image data of BMP is an RGB bare stream, there is a great difficulty in restoring BMP images. At present, no software supporting the restoration of BMP format image files is found at home and abroad. When part of data of a file is lost, normal data needs to be extracted and damaged data needs to be repaired, and because naked stream data does not have a general data format, data at a damaged position is difficult to be accurately positioned, so that perfect image restoration in a BMP format is extremely difficult. Although the user can manually fill data at the end of the image file in the BMP format to open the picture, the picture has the problems of serious deformation, color change and the like.
Disclosure of Invention
The invention aims to provide a BMP picture restoration method and a BMP picture restoration device based on a color gradient principle, so as to solve the problems. Therefore, the invention adopts the following specific technical scheme:
according to an aspect of the present invention, there is provided a BMP picture restoration method, including the steps of:
s1, obtaining information of the damaged BMP picture file from the reference BMP picture file, and the specific process is as follows:
s11, judging whether the palette exists or not by referring to the BMP picture, and if so, entering S12; if not, jumping to S15;
s12, scanning a damaged BMP picture, judging whether the palette is damaged, if so, entering S13, and otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap or not, if so, entering S14, otherwise, failing to repair, and ending the repair;
s14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing to repair the file, judging whether the file head is damaged or not, and if so, jumping to S5; otherwise, go to S2;
s2, self-judging to obtain data of a first reference row, wherein the specific process is as follows:
s21, continuously acquiring the number of bytes needed by one row of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool D is { D ═ D 1 ,D 2 ,D 3 ,…,D n RGB data of the damaged BMP picture;
s22, judging whether the BMP row data has data alignment filling 0, if so, entering S23, otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data, if so, setting the byte number as a reference line RL of the damaged BMP picture file, and jumping to S3, otherwise, entering S24;
s24, discarding one byte, enabling W to be W +1, and if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes; otherwise, the residual data is put back into the data pool D, and the process goes to S25, wherein W is the number of invalid bytes discarded in the repairing process, T is the total number of words required by the damaged BMP picture file, and 50< A < 100;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21, otherwise, failing to repair, and ending the whole process;
s26, acquiring data needed by a row of pixels from the data pool D, and recording the data as L2;
s27, comparing the pixels of the L1 with the pixels of the L2 one by one, judging whether the similar pixels exceed 90%, if so, setting the similar pixels as RL, putting the L1 and the L2 into a set L, and jumping to S3, otherwise, jumping to S24, wherein the set L is { L ═ L { (L) 1 ,L 2 ,L 3 ,…,L n The repaired line data set of the damaged BMP picture is obtained;
s3, repairing line by line, wherein the specific process is as follows:
s31, judging whether the data of the data pool D is larger than the data size required by one line of pixels, if so, entering S32, otherwise, jumping to S4;
s32, continuously acquiring the number of bytes required by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL one by one, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, enabling W to be W +1, judging whether W is larger than A% of T, if so, failing to repair, ending all the processes, otherwise, putting the residual data back into a data pool D, and entering S35;
s35, judging whether the data volume which cannot be similar to the reference line RL is larger than 3 times of the data volume required by the line pixels or not, if so, skipping to S2, reselecting the reference line RL, and otherwise, skipping to S31;
s4, loss data filling, which comprises the following specific processes:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is larger than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
s5, generating a BMP picture file, which comprises the following specific steps:
s51, adjusting BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
Further, a ═ 60.
Further, B ═ 40.
Further, the specific process of determining whether the file header is merely damaged in S16 is as follows: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the data volume into a container T, and continuously taking out one byte from the tail of the container T if the reference BMP picture is a 24-bit true color picture until the taken out byte is 0 or the data of the container T is completely taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; and at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file header is judged to be only damaged.
According to another aspect of the present invention, there is provided a BMP picture restoration device including:
the first module is used for obtaining the information of the damaged BMP picture file from the reference BMP picture file, and the specific process is as follows:
s11, judging whether the palette exists or not by referring to the BMP picture, if so, entering S12, and if not, jumping to S15;
s12, scanning a damaged BMP picture, judging whether the palette is damaged, if so, entering S13, and otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap, if so, entering S14, otherwise, failing in repair, and ending the repair;
s14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing to repair the file, judging whether the file head is damaged or not, if so, jumping to S5, otherwise, entering a second module;
the second module is used for self-judging and obtaining the data of the first reference line, and the specific process is as follows:
s21, continuously acquiring the number of bytes needed by one row of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool D is { D ═ D 1 ,D 2 ,D 3 ,…,D n The RGB data of the damaged BMP picture are used;
s22, judging whether the BMP row data has data alignment filling 0, if so, entering S23, otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data, if so, setting the byte number as a reference line RL of the damaged BMP picture file, and jumping to a third module; otherwise, go to S24;
s24, discarding one byte, enabling W to be W +1, and if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes; otherwise, the rest data is put back into the data pool D, and the S25 is carried out, wherein W is the number of invalid bytes discarded in the repair process, T is the total number of words needed for damaging the BMP picture file, and 50< A < 100;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21, otherwise, failing to repair, and ending the whole process;
s26, acquiring data needed by a row of pixels from the data pool D, and recording the data as L2;
s27, comparing the L1 with the L2 one by one, judging whether similar pixel points exceed 90%, if so, setting the similar pixel points as RL, putting L1 and L2 into a set L, and jumping to a third module, otherwise, jumping to S24, wherein the set L is { L ═ L { (L) 1 ,L 2 ,L 3 ,…,L n The repaired line data set of the damaged BMP picture is obtained;
the third module is used for repairing line by line, and the specific process is as follows:
s31, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, entering S32, otherwise, jumping to a fourth module;
s32, continuously acquiring the number of bytes needed by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL pixel point by pixel point, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, enabling W to be W +1, if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes, otherwise, putting the residual data back into a data pool D, and entering S35;
s35, judging whether the data volume which cannot be similar to the reference line RL at present is larger than 3 times of the data volume required by the line pixels, if so, jumping to a second module, reselecting the reference line RL, and otherwise, jumping to S31;
a fourth module, configured to perform loss data padding, where the specific process is as follows:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is larger than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
and a fifth module, configured to generate a BMP picture file, where the specific process is as follows:
s51, adjusting the BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
Further, a ═ 60.
Further, B ═ 40.
Further, the specific process of determining whether the file header is merely damaged in S16 is as follows: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the HeaderLen into a container T, and if the reference BMP picture is a 24-bit true color picture, continuously taking out a byte from the tail of the container T until the taken out byte is 0 or all the data of the container T are taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; and at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file header is judged to be only damaged.
By adopting the technical scheme, the invention has the beneficial effects that: the method can repair the damaged BMP picture file to a certain extent, creates a precedent of RGB (red, green and blue) bare stream pixel data repair, is a supplement to picture and even video repair algorithms, and has great innovation and practical significance.
Drawings
To further illustrate the various embodiments, the invention provides the accompanying drawings. The accompanying drawings, which are incorporated in and constitute a part of this disclosure, illustrate embodiments of the invention and, together with the description, serve to explain the principles of the embodiments. Those skilled in the art will appreciate still other possible embodiments and advantages of the present invention with reference to these figures. The components in the drawings are not necessarily to scale, and similar reference numerals are generally used to identify similar components.
FIG. 1 is a flow chart of the BMP picture restoration method of the present invention;
FIG. 2 is a schematic block diagram of a BMP picture restoration device of the present invention;
FIG. 3 shows a picture of a damaged BMP;
figure 4 shows pictures of repaired damaged BMPs.
Detailed Description
The invention will now be further described with reference to the drawings and the detailed description.
Brief introduction to BMP Picture File Format
BMP is a standard image file format on windows operating systems. The format is a pixel file that holds all the pixels of an image, and is therefore a bitmap image file format. The number of bytes of each line of the BMP format picture is aligned according to 4 bytes. Standard BMPs may support the storage of monochrome bitmaps, 16 bitmaps, 256 bitmaps, 16 bitmaps, and 24 true color pixel maps. Is one of the most widely used bitmap image formats at present. The Windows operating system has detailed definitions of BMP file structures in the header file of "wingdi.h".
The file is mainly divided into the following 4 parts:
windows definition structure Data structure size Use of
BITMAPFILEHEADER 14 Bitmap file header
BITMAPINFOHEADER 40 Bitmap image information header
Palettes (optional) Image color determination Bitmap palette
BYTE* Image size determination RGB color array
BMP image RGB channel introduction
Monochrome bitmap:
a pixel point of the monochrome bitmap is represented by 1bit, and RGB information of the pixel point is obtained by inquiring the palette, so that the monochrome bitmap only has two colors, namely black and white under the default condition, and is also controlled by the palette.
16 color bit map:
a pixel point of the 16-color bitmap is represented by 4 bits, and RGB information of the pixel point is obtained by inquiring the palette. The 16-color bitmap can have up to 16 colors.
256 color bitmap:
a pixel point of the 256-color bitmap is represented by 8 bits, RGB information of the pixel point is obtained by inquiring the palette, and the 256-color bitmap can have 256 colors at most.
16-bit bitmap:
one pixel of the 16-bit bitmap is represented by 16 bits, and RGB colors can be represented without a palette. The number of bits occupied by the three colors RGB in 16 bits generally has two modes, one is R:5 bits, G:5 bits, B: 5bit, also known as 55516 bit bitmap; and the other R:5bit, G: 6bit, B: 5 bits, called 56516 bit bitmap.
24-bit bitmap:
one pixel point of the 24-bit bitmap is represented by 24 bits, and each RGB occupies 8 bits. The RGB three-color components can be expressed from 0 to 255, and are also called true color images.
RGB color similarity contrast
There are two methods for comparing RGB color similarity, one is to directly calculate RGB color space distance calculation, and the other is to calculate HSV color euler distance contrast after converting into HSV (hue H, saturation S, lightness V). Two comparison methods are described in detail below. Let the RGB colors of the two pixels be r1b1g1 and r2b2g2, respectively.
1) The spatial distance of two colors is calculated, and the spatial distance of the colors is calculated in various ways, and the formula is adopted in the text: diff ═ 255-abs (r1-r2) 0.297-abs (b1-b2) 0.11-abs (g1-g2) 0.593)/255; the smaller the Diff result, the closer the two colors are judged.
2) Converting RGB into HSV, wherein the conversion formula is as follows:
r ' is R/255, G ' is G/255, B ' is B/255,
Cmax=max(R’,G’,B’),Cmin=min(R’,G’,B’),△=Cmax-Cmin,
Hue calculatin:
Figure BDA0002733860570000091
Saturation calculation:
Figure BDA0002733860570000092
Value calculation:
V=Cmax
and directly calculating the Euler distances of the two points after the two pixel points are converted into HSV, wherein the closer the Euler distances are, the closer the colors are.
As shown in fig. 1, a BMP picture restoration method includes the following steps:
s1, obtaining information of a damaged BMP picture file from a reference BMP picture file, wherein the reference BMP picture refers to that the picture size and the bitmap format are the same as those of the damaged BMP picture file, and the specific process is as follows:
s11, judging whether the palette exists or not by referring to the BMP picture, and if so, entering S12; if not, jumping to S15;
s12, scanning the damaged BMP picture, judging whether the palette is damaged, and if so, entering S13; otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap or not, if so, entering S14, otherwise, failing to repair, and ending the repair;
s14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing for file repair, judging whether the file header is damaged or not, if so, jumping to S5, otherwise, entering S2, wherein the specific process of judging whether the file header is damaged or not is as follows: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the data volume into a container T, and continuously taking out one byte from the tail of the container T if the reference BMP picture is a 24-bit true color picture until the taken out byte is 0 or the data of the container T is completely taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file head is judged to be damaged only;
s2, self-judging to obtain data of a first reference row, wherein the specific process is as follows:
s21, continuously acquiring the number of bytes needed by a line of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool is RGB data of a damaged BMP picture;
s22, judging whether the line data of the BMP is aligned with the filling 0 or not, if so, entering S23; otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data; if so, setting the reference line RL of the damaged BMP picture file, and jumping to S3; otherwise, go to S24;
s24, discarding one byte, enabling W to be W +1, and if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes; otherwise, the remaining data is put back into the data pool D, and S25 is entered, where W is the number of invalid bytes discarded by the repair process, T is the total number of words required to damage the BMP picture file, 50< a <100, where a is 60;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21; otherwise, the repair fails, and the whole process is ended;
s26, acquiring data needed by a row of pixels from the data pool D, and marking the data as L2;
s27, comparing the pixels of the L1 with the pixels of the L2 one by one, judging whether the similar pixels exceed 90%, if so, setting the similar pixels as RL, putting the L1 and the L2 into a set L, and jumping to S3, otherwise, jumping to S24, wherein the set L is { L ═ L { (L) 1 ,L 2 ,L 3 ,…,L n Judging similar pixel points to adopt comparison RGB color similarity for a repaired line data set of the damaged BMP picture, and considering the pixel points to be similar when the color space distance Diff of the RGB color similarity is less than 3%;
s3, repairing line by line, wherein the specific process is as follows:
s31, judging whether the data of the data pool D is larger than the data size required by one line of pixels, if so, entering S32, and otherwise, jumping to S4;
s32, continuously acquiring the number of bytes needed by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL one by one, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, judging whether W is greater than A% of T or not, if so, failing to repair, ending all the processes, and if not, returning the residual data to a data pool D and entering S35;
s35, judging whether the data volume which cannot be similar to the reference line RL is larger than 3 times of the data volume required by the line pixels or not, if so, skipping to S2, reselecting the reference line RL, and otherwise, skipping to S31;
s4, loss data filling, which comprises the following specific processes:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is larger than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended, where the size of B depends on the actual requirement, i.e., if the picture is damaged by more than (100-B)%, the repair is not performed, in a specific embodiment, B is 40;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
s5, generating a BMP picture file, which comprises the following specific steps:
s51, adjusting the BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
As shown in fig. 1 and 2, according to another aspect of the present invention, there is provided a BMP picture restoration device including:
the first module 100 is configured to obtain information of a damaged BMP picture file from a reference BMP picture file, and includes the following specific processes:
s11, judging whether the palette exists or not by referring to the BMP picture, and if so, entering S12; if not, jumping to S15;
s12, scanning the damaged BMP picture, judging whether the palette is damaged, and if so, entering S13; otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap or not, and if so, entering S14; otherwise, the repair fails and the repair is finished.
S14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing to repair the file, judging whether the file header is damaged or not, if so, jumping to S5, otherwise, entering a second module 200, wherein the specific process of judging whether the file header is damaged or not is as follows: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the data volume into a container T, and continuously taking out one byte from the tail of the container T if the reference BMP picture is a 24-bit true color picture until the taken out byte is 0 or the data of the container T is completely taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file head is judged to be damaged only;
the second module 200 is configured to obtain data of the first reference line by self-judgment, and includes the following specific processes:
s21, continuously acquiring the number of bytes needed by a row of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool is RGB data of a damaged BMP picture;
s22, judging whether the line data of the BMP is aligned with the filling 0 or not, if so, entering S23; otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data or not; if yes, setting the reference line RL of the damaged BMP picture file, and jumping to the third module 300; otherwise, the process proceeds to S24.
S24, discarding one byte, judging whether W is greater than A% of T or not, if so, failing to repair, and ending all the processes; otherwise, the remaining data is put back into the data pool D, and S25 is entered, where W is the number of invalid bytes discarded by the repair process, T is the total number of words required to damage the BMP picture file, 50< a <100, where a is 60;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21; otherwise, the repair fails, and the whole process is ended;
s26, acquiring data needed by a row of pixels from the data pool D, and recording the data as L2;
s27, comparing the L1 with the L2 one by one, judging whether the similar pixel points exceed 90%, if so, setting the similar pixel points as RL, putting L1 and L2 into a set L, and jumping to the third module 300, otherwise, jumping to S24, wherein the set L is { L ═ L { (L) 1 ,L 2 ,L 3 ,…,L n Judging similar pixel points to adopt comparison RGB color similarity for a repaired line data set of the damaged BMP picture, and considering the pixel points to be similar when the color space distance Diff of the RGB color similarity is less than 3%;
the third module 300 is configured to perform line-by-line repair, and includes the following specific processes:
s31, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, entering S32, otherwise, jumping to the fourth module 400;
s32, continuously acquiring the number of bytes needed by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL pixel point by pixel point, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, judging whether W is greater than A% of T or not, if so, failing to repair, ending all the processes, and if not, returning the residual data to a data pool D and entering S35;
s35, whether the data volume which cannot be similar to the reference line RL at present is larger than 3 times of the data volume required by the line pixels or not is judged, if yes, the second module 200 is skipped to, the reference line RL is reselected, and otherwise, the S31 is skipped to;
a fourth module 400, configured to perform loss data padding, where the specific process is as follows:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is greater than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended, where the size of B depends on the actual requirement, i.e., if the picture is damaged by more than (100-B)%, the repair is not performed, in a specific embodiment, B is 40;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
and a fifth module 500, configured to generate a BMP picture file, where the specific process is as follows:
s51, adjusting the BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
And (3) experimental test verification:
1) shooting two BMP pictures with the same pixel by using a digital camera or acquiring two standard BMP pictures with the same pixel by using a network, and acquiring two 24-bit true color pictures from the network at this time to perform an experiment;
2) randomly breaking a BMP picture, as shown in FIG. 3;
3) the perfect BMP picture is taken as a reference picture, the picture is repaired by using the method, and the repaired picture is shown as a picture in figure 4. It is noted here that since the patent law states that the drawings cannot employ color pictures, fig. 4 is processed into a gray scale display.
The invention provides a BMP picture restoration method based on a color gradient principle, which can extract self reference data from RGB (red, green and blue) bare stream data and carry out line comparison and macro block comparison in a BMP bitmap image, thereby realizing BMP picture restoration. The method expands the picture restoration mode and creates a precedent of RGB bare stream pixel data restoration, is a supplement to the picture and even video restoration algorithm, and has great innovation and practical significance.
While the invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.

Claims (10)

1. A BMP picture repairing method is characterized by comprising the following steps:
s1, obtaining information of the damaged BMP picture file from the reference BMP picture file, and the specific process is as follows:
s11, judging whether the palette exists or not by referring to the BMP picture, and if so, entering S12; if not, jumping to S15;
s12, scanning the damaged BMP picture, judging whether the palette is damaged, if so, entering S13, otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap or not, if so, entering S14, otherwise, failing to repair, and ending the repair;
s14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing to repair the file, judging whether the header of the file is damaged only, and if so, jumping to S5; otherwise, entering S2;
s2, self-judging to obtain data of a first reference row, wherein the specific process is as follows:
s21, continuously acquiring the number of bytes needed by one row of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool D is { D ═ D 1 ,D 2 ,D 3 ,…,D n RGB data of the damaged BMP picture;
s22, judging whether the line data of the BMP are aligned with the filling 0, if so, entering S23, otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data, if so, setting the byte number as a reference line RL of the damaged BMP picture file, and jumping to S3, otherwise, entering S24;
s24, discarding one byte, enabling W to be W +1, and if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes; otherwise, the residual data is put back into the data pool D, and the process goes to S25, wherein W is the number of invalid bytes discarded in the repairing process, T is the total number of words required by the damaged BMP picture file, and 50< A < 100;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21, otherwise, failing to repair, and ending the whole process;
s26, acquiring data needed by a row of pixels from the data pool D, and recording the data as L2;
s27, comparing the L1 with the L2 one by one, judging whether similar pixel points exceed 90%, if so, setting the similar pixel points as RL, putting L1 and L2 into a set L, and jumping to S3, otherwise, jumping to S24, wherein the set L is { L ═ L { (L) 1 ,L 2 ,L 3 ,…,L n The repaired line data set of the damaged BMP picture is obtained;
s3, repairing line by line, wherein the specific process is as follows:
s31, judging whether the data of the data pool D is larger than the data size required by one line of pixels, if so, entering S32, otherwise, jumping to S4;
s32, continuously acquiring the number of bytes needed by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL pixel point by pixel point, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, enabling W to be W +1, judging whether W is larger than A% of T, if so, failing to repair, ending all the processes, otherwise, putting the residual data back into a data pool D, and entering S35;
s35, judging whether the data volume which cannot be similar to the reference line RL is larger than 3 times of the data volume required by the line pixels or not, if so, skipping to S2, reselecting the reference line RL, and otherwise, skipping to S31;
s4, filling loss data, which comprises the following specific processes:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is greater than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
s5, generating a BMP picture file, which comprises the following specific steps:
s51, adjusting the BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
2. The BMP picture restoration method of claim 1, wherein a is 60.
3. The BMP picture restoration method of claim 1, wherein B-40.
4. The BMP picture restoration method of claim 1, wherein the specific process of determining whether the file header is merely damaged in S16 is: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the HeaderLen into a container T, and if the reference BMP picture is a 24-bit true color picture, continuously taking out a byte from the tail of the container T until the taken out byte is 0 or all the data of the container T are taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; and at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file header is judged to be only damaged.
5. The BMP picture restoration method of claim 1, wherein the comparison of RGB color similarity is used to determine similar pixel points.
6. A BMP picture restoration device, comprising:
the first module is used for acquiring information of the damaged BMP picture file from the reference BMP picture file, and the specific process is as follows:
s11, judging whether the palette exists or not by referring to the BMP picture, if so, entering S12, and if not, jumping to S15;
s12, scanning a damaged BMP picture, judging whether the palette is damaged, if so, entering S13, and otherwise, jumping to S15;
s13, judging whether the bitmap is a monochrome bitmap or not, if so, entering S14, otherwise, failing to repair, and ending the repair;
s14, setting a monochrome bitmap palette as black and white bright colors;
s15, acquiring row pixel points and column pixel points of the picture from the reference BMP picture file, and generating header information of the damaged BMP picture;
s16, reading the damaged BMP picture file, preparing to repair the file, judging whether the file head is damaged or not, if so, jumping to S5, otherwise, entering a second module;
the second module is used for self-judging and acquiring the data of the first reference line, and the specific process is as follows:
s21, continuously acquiring the number of bytes needed by one row of pixels from a data pool D, and recording the number of bytes as L1, wherein the data pool D is { D ═ D 1 ,D 2 ,D 3 ,…,D n The RGB data of the damaged BMP picture are used;
s22, judging whether the BMP row data has data alignment filling 0, if so, entering S23, otherwise, jumping to S26;
s23, judging whether the byte number of 0 filled at the tail of the L1 is consistent with the alignment data, if so, setting the byte number as a reference line RL of the damaged BMP picture file, and jumping to a third module; otherwise, entering S24;
s24, discarding one byte, enabling W to be W +1, judging whether W is larger than A% of T, if so, failing to repair, and ending all the processes; otherwise, the residual data is put back into the data pool D, and the process goes to S25, wherein W is the number of invalid bytes discarded in the repairing process, T is the total number of words required by the damaged BMP picture file, and 50< A < 100;
s25, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, jumping to S21, otherwise, failing to repair, and ending the whole process;
s26, acquiring data needed by a row of pixels from the data pool D, and recording the data as L2;
s27, comparing the pixels of the L1 with the pixels of the L2 one by one, judging whether the similar pixels exceed 90%, if so, setting the similar pixels as RL, putting the L1 and the L2 into a set L, and jumping to a third module, otherwise, jumping to S24, wherein the set L is { L ═ L { (L } L 1 ,L 2 ,L 3 ,…,L n The repaired line data set of the damaged BMP picture is obtained;
the third module is used for repairing line by line, and the specific process is as follows:
s31, judging whether the data of the data pool D is larger than the data quantity required by one line of pixels, if so, entering S32, otherwise, jumping to a fourth module;
s32, continuously acquiring the number of bytes required by a row of pixels from the data pool D, and recording the number of bytes as Li;
s33, comparing the Li with the RL pixel point by pixel point, judging whether the similar pixel points exceed 90%, if so, putting the Li into a set L, taking the Li as the RL, and jumping to S31, otherwise, jumping to S34;
s34, discarding one byte, enabling W to be W +1, if W is larger than A% of T, failing to repair if W is larger than A%, and ending all the processes, otherwise, putting the residual data back into a data pool D, and entering S35;
s35, judging whether the data volume which cannot be similar to the reference line RL is larger than 3 times of the data volume required by the line pixels or not, if so, skipping to a second module, reselecting the reference line RL, and otherwise, skipping to S31;
a fourth module, configured to perform loss data padding, where the specific process is as follows:
s41, calculating the total data amount of the pixels of all the rows in the set L, judging whether the total data amount is greater than B% of T, and if yes, entering S42; otherwise, the repair fails, and the whole process is ended;
s42, calculating the data difference between the total data amount of the pixels of all the rows in the set L and the data difference T, generating blank rows with corresponding data amounts, putting the blank rows into the set L, and entering S5;
and a fifth module, configured to generate a BMP picture file, where the specific process is as follows:
s51, adjusting the BMP header information to be matched with the set L;
and S52, generating a file for repairing the BMP picture.
7. The BMP picture restoration device of claim 6, wherein a-60.
8. The BMP picture restoration device of claim 6, wherein B-40.
9. The BMP picture restoration device of claim 6, wherein the specific process of determining whether only the file header is damaged in S16 is: acquiring the header length HeaderLen of a reference BMP picture file, reading the data volume of the HeaderLen from the damaged BMP picture file, putting the data volume into a container T, and continuously taking out one byte from the tail of the container T if the reference BMP picture is a 24-bit true color picture until the taken out byte is 0 or the data of the container T is completely taken out; if the reference picture is not the 24-bit true color picture, continuously taking out one byte from the end of the container T until the taken byte is 0xff or all the data of the container T are taken out; and at the moment, the number of the remaining bytes of the container T is RemindLen, whether the size of the damaged BMP picture file plus HeaderLen-RemindLen is equal to the size of the reference BMP picture file or not is judged, and if yes, the file header is judged to be only damaged.
10. The BMP picture restoration device of claim 6, wherein the comparison RGB color similarity is used for determining similar pixel points.
CN202011126750.5A 2020-10-20 2020-10-20 BMP picture restoration method and device Active CN112215775B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011126750.5A CN112215775B (en) 2020-10-20 2020-10-20 BMP picture restoration method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011126750.5A CN112215775B (en) 2020-10-20 2020-10-20 BMP picture restoration method and device

Publications (2)

Publication Number Publication Date
CN112215775A CN112215775A (en) 2021-01-12
CN112215775B true CN112215775B (en) 2022-09-06

Family

ID=74056067

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011126750.5A Active CN112215775B (en) 2020-10-20 2020-10-20 BMP picture restoration method and device

Country Status (1)

Country Link
CN (1) CN112215775B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005301524A (en) * 2004-04-08 2005-10-27 Olympus Corp Image processing program, method and apparatus
CN101510303A (en) * 2009-03-26 2009-08-19 北京兆维科技股份有限公司 Method and system for image renovation
CN102567970A (en) * 2011-12-29 2012-07-11 方正国际软件有限公司 Image restoring method and device
CN108961193A (en) * 2018-08-10 2018-12-07 厦门市美亚柏科信息股份有限公司 A kind of image repair method, device and storage medium
CN110728639A (en) * 2019-09-29 2020-01-24 三星电子(中国)研发中心 Picture repairing method and system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050289182A1 (en) * 2004-06-15 2005-12-29 Sand Hill Systems Inc. Document management system with enhanced intelligent document recognition capabilities

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005301524A (en) * 2004-04-08 2005-10-27 Olympus Corp Image processing program, method and apparatus
CN101510303A (en) * 2009-03-26 2009-08-19 北京兆维科技股份有限公司 Method and system for image renovation
CN102567970A (en) * 2011-12-29 2012-07-11 方正国际软件有限公司 Image restoring method and device
CN108961193A (en) * 2018-08-10 2018-12-07 厦门市美亚柏科信息股份有限公司 A kind of image repair method, device and storage medium
CN110728639A (en) * 2019-09-29 2020-01-24 三星电子(中国)研发中心 Picture repairing method and system

Also Published As

Publication number Publication date
CN112215775A (en) 2021-01-12

Similar Documents

Publication Publication Date Title
AU2002300994B2 (en) Method and Apparatus for Processing Image Data, Storage Medium and Program
US8478039B2 (en) Information processing device and method and program
JP2005141222A (en) Method and apparatus for enhancing local luminance of video, and computer-readable recording medium with computer program stored thereto
US10783667B2 (en) Information processing device and method, and program, for gamut conversion of content
US9270865B2 (en) Recording device and recording control method, reproduction device and reproduction control method, output device and output control method, and programs
EP3211892A1 (en) Method and device for image display based on metadata, and recording medium therefor
US8860745B2 (en) System and method for color gamut mapping
US6961460B2 (en) Dual mode digital picture signal processing
CN101686321A (en) Method and system for reducing noise in image data
EP1850290B1 (en) Image processing apparatus and method for preventing degradation of image quality when bit format of image is converted
CN112215775B (en) BMP picture restoration method and device
CN114697523A (en) Method and system for correcting shooting parameters of camera, display equipment and storage medium
CN101925921A (en) Image signal processing device and image signal processing program
US20190079930A1 (en) Systems and methods for rendering graphical assets
US20210407400A1 (en) Image display system for displaying high dynamic range image
CN101287057A (en) Buffer saving image decompressing storing method and module thereof
Gish et al. Unambiguous video pipeline description motivated by HDR
CN103685853A (en) Image processing apparatus and image processing method
JP2022007871A (en) Image generation apparatus, display apparatus, control method, system, program, and storage medium
JP2015100129A (en) Output adjustment of image data
Zeng Color encoding for gamut extension and bit-depth extension
CN118115411A (en) Compensation display method of HDR (high-definition digital range) image, storage medium, mobile terminal and vehicle
KR20040073722A (en) Apparatus and Method for improving quality of picture in mobile terminal attatched digital camera
JP2006174490A (en) Output adjustment of image data
JP2016067040A (en) Image data output adjusting device, image data output adjustment method, image data output adjustment program, and imaging apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant