Summary of the invention
In view of above-mentioned the deficiencies in the prior art, the object of the present invention is to provide a kind of lossless compression method for the homochromy picture in edge and system, being intended to solve current picture, to take memory space large, cannot carry out the problem of Lossless Compression.
Technical scheme of the present invention is as follows:
For a lossless compression method for the homochromy picture in edge, wherein, said method comprising the steps of:
A, obtain the picture format of picture and this picture is converted to the view data of rgb format;
B, according to the view data of rgb format after conversion, detect this picture and whether have homochromy region, edge, if exist, record and preserve rgb image data corresponding to homochromy region, described edge;
C, this picture except converting former picture format to, the homochromy extra-regional view data in described edge is preserved.
The described lossless compression method for the homochromy picture in edge, wherein, described edge is homochromy, and region refers to that image edge exists the region of same color value.
The described lossless compression method for the homochromy picture in edge, wherein, described edge is homochromy, and rgb image data corresponding to region refers to color value and the area information that homochromy region, edge is corresponding.
The described lossless compression method for the homochromy picture in edge, wherein, described step B specifically comprises:
B1,4 limits based on picture are divided into 4 rectangular edges districts by the edge of picture, obtain the wherein rgb image data of a summit pixel in each rectangular edges district;
Whether B2, the rgb image data that judges successively each pixel in each rectangular edges district be identical with the rgb image data of the summit pixel in obtained this rectangular edges district, if identical, records and preserve color value and the area information of this pixel.
The described lossless compression method for the homochromy picture in edge, wherein, in described step B2, the identical pixel of rgb image data to each rectangular edges district Zhong Yugai rectangular edges district summit pixel, preserves color value and the area information of each pixel according to the sequencing of record.
The described lossless compression method for the homochromy picture in edge, wherein, described method also comprises:
D, the view data by the rgb image data in preserved homochromy region, described edge in conjunction with the homochromy region of non-flanged of preserving decompress, and obtain the image data before this picture compression.
The described lossless compression method for the homochromy picture in edge, wherein, described step D is specially:
D1, the rgb image data inverted sequence in preserved homochromy region, described edge is arranged;
D2, the picture in the preserved homochromy region of non-flanged is partly converted to the view data of rgb format;
Described in the rgb image data in D3, homochromy region, edge that described inverted sequence is arranged adds to one by one, convert on the picture in the homochromy region of non-flanged after rgb format and form rgb format picture;
D4, by rgb format, convert formed rgb format picture to former picture format.
A system with the lossless compression method for the homochromy picture in edge as above, wherein, described system comprises compression module, described compression module comprises:
The first picture format converting unit, for obtaining the picture format of picture and this picture being converted to the view data of rgb format, and converts this picture to former picture format except the homochromy extra-regional view data in described edge;
Whether image edge is homochromy regional record unit, there is homochromy region, edge for detecting this picture according to the view data of the rgb format after conversion, if exist, records rgb image data corresponding to homochromy region, described edge;
Picture storage unit, for preserve rgb image data corresponding to homochromy region, described edge and convert to former picture format except the homochromy extra-regional view data in described edge.
The described Lossless Compression system for the homochromy picture in edge, wherein, described system also comprises:
Decompression module, for the view data in conjunction with the homochromy region of non-flanged of preserving decompresses by the rgb image data in preserved homochromy region, described edge, obtains the image data before this picture compression.
The described Lossless Compression system for the homochromy picture in edge, wherein, described decompression module also comprises:
Second picture format conversion unit, for partly converting the picture in the preserved homochromy region of non-flanged to the view data of rgb format and converting formed rgb format picture to former picture format by rgb format;
Picture recovery unit, converts to described in adding to one by one on the picture in the homochromy region of non-flanged after rgb format form rgb format picture for the rgb image data in the homochromy region, edge of the rgb image data inverted sequence in preserved homochromy region, described edge being arranged and described inverted sequence being arranged.
Beneficial effect: the invention provides a kind of lossless compression method for the homochromy picture in edge and system, by processing thering is the picture at homochromy edge, make in such picture compression process, its edge and other parts are preserved respectively, realized and not reduced under the prerequisite of picture quality, saved the object in picture-storage space.
Embodiment
The invention provides a kind of lossless compression method for the homochromy picture in edge and system, for making object of the present invention, technical scheme and effect clearer, clear and definite, below the present invention is described in more detail.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
A kind of lossless compression method for the homochromy picture in edge as shown in Figure 1, wherein, said method comprising the steps of:
S100, obtain the picture format of picture and this picture is converted to the view data of rgb format.
Because picture format is of a great variety, for example JPEG, BMP, PNG etc., convert different types of picture to by this step the view data being represented by RGB, and in picture, each pixel represents with one group of rgb image data.
S200, according to the view data of rgb format after conversion, detect this picture and whether have homochromy region, edge, if exist, record and preserve rgb image data corresponding to homochromy region, described edge.
Described edge is homochromy, and region refers to that image edge exists the region of same color value.And concrete, described edge is homochromy, and rgb image data corresponding to region refers to color value and the area information that homochromy region, edge is corresponding.
In preferred embodiment, described step S200 comprises as shown in Figure 2:
S210,4 limits based on picture are divided into 4 rectangular edges districts by the edge of picture, obtain the wherein rgb image data of a summit pixel in each rectangular edges district.
Whether S220, the rgb image data that judges successively each pixel in each rectangular edges district be identical with the rgb image data of the summit pixel in obtained this rectangular edges district, if identical, records and preserve color value and the area information of this pixel.In preferred embodiment, the identical pixel of rgb image data to each rectangular edges district Zhong Yugai rectangular edges district summit pixel, preserves color value and the area information of each pixel according to the sequencing of record.
The specific embodiment detecting for homochromy region, edge can make an explanation in conjunction with picture as shown in Figure 3, and the picture size shown in figure is x1 * y1.Rectangle picture is divided into San, edge, Er, edge, Yi, edge, edge 44 parts according to the position on 4 limits, and can carries out according to step as shown in Figure 4:
S201, a counter C is set, and zero setting, perform step afterwards S202;
S202, judge whether edge one exists homochromy region, edge, if it is performs step S203, otherwise execution step S204;
S203, record edge together size and the homochromy RGB data in look region, and by this homochromy region excision, by C zero setting, perform step afterwards S206; The meaning of excision first will be got rid of after this homochromy area information record in detection range afterwards, and the picture finally staying is partly the part in the homochromy region of non-flanged.
S204, C is added to 1, C equals C and adds 1, performs step afterwards S205;
S205, judge whether C equals 4, if it is performs step S218, otherwise execution step S206;
S206, judge whether edge two exists homochromy region, edge, if it is performs step S207, otherwise execution step S208;
S207, record size and the homochromy RGB data in two homochromy regions, edge, and by this homochromy region excision, by C zero setting, perform step afterwards S210;
S208, C is added to 1, C equals C and adds 1, performs step afterwards S209;
S209, judge whether C equals 4, if it is performs step S218, otherwise execution step S210;
S210, judge whether edge three exists homochromy region, edge, if it is performs step S211, otherwise execution step S212;
S211, record size and the homochromy RGB data in three homochromy regions, edge, and by this homochromy region excision, by C zero setting, perform step afterwards S214;
S212, C is added to 1, C equals C and adds 1, performs step afterwards S213;
S213, judge whether C equals 4, if it is performs step S218, otherwise execution step S214;
S214, judge whether edge four exists homochromy region, edge, if it is performs step S215, otherwise execution step S216;
S215, record size and the homochromy RGB data in four homochromy regions, edge, and by this homochromy region excision, by C zero setting, perform step afterwards S202;
S216, C is added to 1, C equals C and adds 1, performs step afterwards S217;
S217, judge whether C equals 4, if it is performs step S218, otherwise execution step S217;
S218, edge is homochromy region are detected complete.
In preferred embodiment, for the detection detailed step of described step S202 and S203 edge one as shown in Figure 5, comprise the steps.
The RGB data of each pixel of picture of S501, input size x1 * y1, perform step S502 afterwards;
S502, obtain P(1,1), perform step afterwards S503; Use P(x, y herein) represent that coordinate is the RGB data of the point of (x, y);
S503, variable x is set, y, and all put 1, perform step afterwards S504;
S504, judge whether y is less than or equal to y1, if it is performs step S505, otherwise execution step S513;
S505, x is set is 1, performs step afterwards S506;
S506, judge whether x is less than or equal to x1, if it is performs step S508, otherwise execution step S507;
S507, variable y is added to 1, y equals y and adds 1, performs step afterwards S504;
S508, judgement P(x, y) whether equal P(1,1) if it is perform step S509, otherwise execution step S510;
S509, variable x is added to 1, x equals x and adds 1, performs step afterwards S506;
S510, judge whether y is greater than 1, if it is performs step S512, otherwise execution step S511;
There is not homochromy region in S511, edge one, performs step afterwards S204;
S512, record the together information in look region of edge, recording mode is as follows: edge one, size x1 * (y-1), color P(1,1) rgb value, perform step afterwards S513;
S513, the RGB data of each pixel that preferably input are of a size of to the picture of x1 * y1 cut together look region, edge, are about to the region excision that edge one is of a size of x1 * (y-1).
In preferred embodiment, for the detection detailed step of above-mentioned steps S206 and S207 edge two as shown in Figure 6, comprise the steps.
The RGB data of each pixel of picture of S601, input size x1 * y1, perform step S602 afterwards;
S602, obtain P(x1,1), perform step afterwards S603; Use P(x, y herein) represent that coordinate is the RGB data of the point of (x, y);
S603, variable x is set, y, and x is set is x1, y is 1, performs step afterwards S604;
S604, judge whether x is more than or equal to 1, if it is performs step S605, otherwise execution step S613;
S605, y is set is 1, performs step afterwards S606;
S606, judge whether y is less than or equal to y1, if it is performs step S608, otherwise execution step S607;
S607, variable x is subtracted to 1, x equals x and subtracts 1, performs step afterwards S604;
S608, judgement P(x, y) whether equal P(x1,1) if it is perform step S609, otherwise execution step S610;
S609, variable y is added to 1, y equals y and adds 1, performs step afterwards S606;
S610, judge whether x is less than x1, if it is performs step S612, otherwise execution step S611;
There is not homochromy region in S611, edge two, performs step afterwards S208;
S612, record the information in two homochromy regions, edge, recording mode is as follows: edge two, size (x1-x) * y1, color P(x1,1) rgb value, perform step afterwards S613;
S613, the RGB data of each pixel that input is of a size of to the picture of x1 * y1 cut homochromy region, edge two, are about to the region excision that edge two is of a size of (x1-x) * y1.
In preferred embodiment, for the detection detailed step of above-mentioned steps S210 and S211 edge three as shown in Figure 7, comprise the steps.
The RGB data of each pixel of picture of S701, input size x1 * y1, perform step S702 afterwards;
S702, obtain P(x1, y1), perform step afterwards S703; Use P(x, y herein) represent that coordinate is the RGB data of the point of (x, y);
S703, variable x is set, y, and x is set is x1, y is y1, performs step afterwards S704;
S704, judge whether y is more than or equal to 1, if it is performs step S705, otherwise execution step S713;
S705, x is set is x1, performs step afterwards S706;
S706, judge whether x is more than or equal to 1, if it is performs step S708, otherwise execution step S707;
S707, variable y is subtracted to 1, y equals y and subtracts 1, performs step afterwards S704;
S708, judgement P(x, y) whether equal P(x1, y1) if it is perform step S709, otherwise execution step S710;
S709, variable x is subtracted to 1, x equals x and subtracts 1, performs step afterwards S706;
S710, judge whether y is less than y1, if it is performs step S712, otherwise execution step S711;
There is not homochromy region in S711, edge three, performs step afterwards S212;
S712, record the information in three homochromy regions, edge, recording mode is as follows: edge three, size x1 * (y1-y), color P(x1, y1) rgb value, perform step afterwards S713;
S713, the RGB data of each pixel that input is of a size of to the picture of x1 * y1 cut homochromy region, edge three, are about to the region excision that edge three is of a size of x1 * (y1-y).
In preferred embodiment, for the detection detailed step of above-mentioned steps S214 and S215 edge four as shown in Figure 8, comprise the steps.
The RGB data of each pixel of picture of S801, input size x1 * y1, perform step S802 afterwards;
S802, obtain P(1, y1), perform step afterwards S803; Use P(x, y herein) represent that coordinate is the RGB data of the point of (x, y);
S803, variable x is set, y, and x is set is that 1, y is y1, performs step afterwards S804;
S804, judge whether x is less than or equal to x1, if it is performs step S805, otherwise execution step S813;
S805, y is set is y1, performs step afterwards S806;
S806, judge whether y is more than or equal to 1, if it is performs step S808, otherwise execution step S807;
S807, variable x is added to 1, x equals x and adds 1, performs step afterwards S804;
S808, judgement P(x, y) whether equal P(1, y1) if it is perform step S809, otherwise execution step S810;
S809, variable y is subtracted to 1, y equals y and subtracts 1, performs step afterwards S806;
S810, judge whether x is greater than 1, if it is performs step S812, otherwise execution step S811;
There is not homochromy region in S811, edge four, performs step afterwards S216;
S812, record the information in four homochromy regions, edge, recording mode is as follows: edge four, size (x-1) * y1, color P(1, y1) rgb value, perform step afterwards S813;
S813, the RGB data of each pixel that input is of a size of to the picture of x1 * y1 cut homochromy region, edge four, are about to the region excision that edge four is of a size of (x-1) * y1.
S300, this picture except converting former picture format to, the homochromy extra-regional view data in described edge is preserved.
In addition, described method also comprises:
View data by the rgb image data in preserved homochromy region, described edge in conjunction with the homochromy region of non-flanged of preserving decompresses, and obtains the image data before this picture compression.
In preferred embodiment, above-mentioned decompression step is specially as shown in Figure 9:
S410, the rgb image data inverted sequence in preserved homochromy region, described edge is arranged;
S420, the picture in the preserved homochromy region of non-flanged is partly converted to the view data of rgb format;
Described in the rgb image data in S430, homochromy region, edge that described inverted sequence is arranged adds to one by one, convert on the picture in the homochromy region of non-flanged after rgb format and form rgb format picture;
S440, by rgb format, convert formed rgb format picture to former picture format.Generate the picture form before this picture compression.
Utilize the carry out compression and decompression of above-mentioned method to picture as shown in figure 10, this picture unprocessed form is BMP picture format, and central authorities have the several letters of TCL, and remaining edge is partly that solid color pixel forms, and concrete implementation step is:
Compression process for this picture is as follows:
Step 1, obtain picture format, and this picture is changed into rgb format; This picture is turned to RGB through BMP;
Whether step 2, detection there is homochromy region, edge, if existed, color value and regional record that edge in RGB data is homochromy get off: edge one, size XX1 * YY1, color 1; Edge two, size XX2 * YY2, color 2; Edge three, size XX3 * YY3, color 3; Edge four, size XX4 * YY4, color 4;
Step 3, the rgb format picture of the homochromy region A of remaining non-flanged is changed into the original form of this picture, the RGB data in this homochromy region of non-flanged turn BMP by RGB;
The homochromy picture of non-flanged of step 4, the homochromy region, all edges of preserving step 2 record and step 3 record.
After above-mentioned compression, this picture is carried out to decompression process as follows:
Step 5, obtain the information of preserved picture after overcompression, comprise, non-flanged is homochromy picture and according to the homochromy area information in edge of sequencing record;
Step 6, convert the homochromy picture of non-flanged to rgb format; Carry out BMP and turn RGB;
Step 7, by the homochromy area information inverted sequence in the edge recording obtaining in step 5; Be about to following information inverted sequence, edge one, size XX1 * YY1, color 1; Edge two, size XX2 * YY2, color 2; Edge three, size XX3 * YY3, color 3; Edge four, size XX4 * YY4, color 4;
Step 8, the homochromy area information in the edge after inverted sequence is added on the picture of the rgb format generating in step 6 one by one; In its left interpolation, be of a size of XX4 * YY4, color is the RGB data of color 4; Add and be of a size of XX3*YY3 thereon, color is the RGB data of color 3; In its right interpolation, be of a size of XX2 * YY2, color is the RGB data of color 2; Its lower interpolation, be of a size of XX4 * YY4, color is the RGB data of color 4;
Step 9, the picture of the rgb format generating in step 8 is converted to the unprocessed form of this picture; Carry out RGB and turn BMP; The picture that this step generates is the picture before this picture compression.
A kind of system with the lossless compression method for the homochromy picture in edge as above as shown in figure 11, wherein, described system is arranged in central processing unit 100, this system comprises for to the compression module 200 that exists homochromy region, edge picture to compress to preserve with for the view data in conjunction with the homochromy region of non-flanged of preserving decompresses by the rgb image data in preserved homochromy region, described edge, obtains the decompression module 300. of the image data before this picture compression
Wherein, as shown in figure 12, described compression module comprises:
The first picture format converting unit 210, be used for the view data of obtaining the picture format of picture and this picture being converted to rgb format, and convert this picture to former picture format except the homochromy extra-regional view data in described edge, specifically as described in step S100 and S300.
In preferred embodiment, the first picture format converting unit comprises as shown in figure 13: for obtaining the picture format acquiring unit 211 of the form of input picture and the picture format of the final output of needs, and also comprise the unit of changing between various picture formats, as PNG turns RGB unit 212, BMP, turn RGB unit 213, JPEG and turn RGB unit 214, RGB and turn that PNG unit 215, RGB turn BMP unit 216, RGB turns JPEG unit 217 etc.; The form of the form of the input picture that format acquisition unit 211 is obtained and output picture selects corresponding unit to carry out picture format conversion in 112~unit, unit 117.
Whether image edge is homochromy regional record unit 220, there is homochromy region, edge for detecting this picture according to the view data of the rgb format after conversion, if exist, records rgb image data corresponding to homochromy region, described edge, specifically as described in step S200.
Picture storage unit 230, for preserve rgb image data corresponding to homochromy region, described edge and convert to former picture format except the homochromy extra-regional view data in described edge, specifically as described in step S200 and S300.
In preferred embodiment, as shown in figure 14, described decompression module also comprises:
Second picture format conversion unit 310, for the picture in the preserved homochromy region of non-flanged is partly converted to the view data of rgb format and converts formed rgb format picture to former picture format by rgb format, specifically as described in step S420 and S440.Described second picture format conversion unit and described the first picture format converting unit function class seemingly, do not repeat.
Picture recovery unit 320, described in adding to one by one for the rgb image data in the homochromy region, edge of the rgb image data inverted sequence in preserved homochromy region, described edge being arranged and described inverted sequence being arranged, convert on the picture in the homochromy region of non-flanged after rgb format and form rgb format picture, specifically as described in step S410 and S430.
The invention provides a kind of lossless compression method for the homochromy picture in edge and system, by processing thering is the picture at homochromy edge, make in such picture compression process, its edge and other parts are preserved respectively, realized and not reduced under the prerequisite of picture quality, saved the object in picture-storage space.
Should be understood that, application of the present invention is not limited to above-mentioned giving an example, and for those of ordinary skills, can be improved according to the above description or convert, and all these improvement and conversion all should belong to the protection range of claims of the present invention.