WO2020029895A1 - 一种图像修复方法、装置及存储介质 - Google Patents

一种图像修复方法、装置及存储介质 Download PDF

Info

Publication number
WO2020029895A1
WO2020029895A1 PCT/CN2019/099119 CN2019099119W WO2020029895A1 WO 2020029895 A1 WO2020029895 A1 WO 2020029895A1 CN 2019099119 W CN2019099119 W CN 2019099119W WO 2020029895 A1 WO2020029895 A1 WO 2020029895A1
Authority
WO
WIPO (PCT)
Prior art keywords
image
repaired
data
header file
huffman
Prior art date
Application number
PCT/CN2019/099119
Other languages
English (en)
French (fr)
Inventor
钟臻
翟晓飞
沈长达
吴少华
Original Assignee
厦门市美亚柏科信息股份有限公司
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 厦门市美亚柏科信息股份有限公司 filed Critical 厦门市美亚柏科信息股份有限公司
Publication of WO2020029895A1 publication Critical patent/WO2020029895A1/zh

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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T9/00Image coding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N9/00Details of colour television systems
    • H04N9/64Circuits for processing colour signals

Definitions

  • the present disclosure relates to the field of image processing technology, and in particular, to an image repair method, device, and storage medium.
  • JPG is an image format. Due to its efficient compression efficiency and standardization requirements, JPG images have been widely used in color fax, mobile phone storage, camera storage, conference calls, e-commerce and news image transmission. Therefore, JPG image recovery technology has been a hot spot in the field of computer security. At present, the traditional data recovery software has a relatively low repair rate for damaged images, especially those with missing heads.
  • JPG data recovery technology has received extensive attention and research.
  • Existing JPG file recovery technologies use the signature recovery method or the file system-based fragment reorganization method to recover related files, but they cannot do anything with JPG files with missing head signatures.
  • JPG file recovery technologies are implemented by analyzing file system-based fragment reorganization or signature recovery. When the coding area is covered by other data, the open file appears to be unreadable.
  • An image repair method includes:
  • the image to be repaired is repaired based on the correct header file to obtain a repaired image.
  • the image to be repaired is an image in jpg format.
  • the operation of obtaining the correct header file is: obtaining an intact image of the header file generated by using the same software or equipment as the image to be repaired, and obtaining the header file of the intact image of the header file as the Describes the correct header file for the image to be repaired.
  • step (1) (4) Decode Cb DC coefficient value and AC coefficient value according to Huffman tree DCT 0 , DCT 1 ACT 0, and ACT 1. If decoding is successful, continue to step (1), if decoding fails, continue to process the next pending in the DS set. Repair the data block and continue with step (1);
  • DcCount> (Width / McuCount) * 3. If yes, it means that a piece of data is pre-decoded. If not, if it is MCULINE, > MCU_MAX, if yes, end the processing, where MCULINE is the number of the data block currently being processed to be repaired, and MCU_MAX is the total number of data blocks to be repaired;
  • DC [i] is an element in the DCF set
  • M is the image width
  • N is the current value of DcCount
  • Average is the smoothness of the image
  • the method further includes:
  • a correction step of correcting position, brightness and chroma of the repaired image is a correction step of correcting position, brightness and chroma of the repaired image.
  • N is the number of decoded DC coefficients
  • WIDTH is the width of the image
  • OFFSET is the offset of the elements in the DCF set
  • W_OFFSET (WIDTH-i) / (Hmax * Vmax), where W_OFFSET represents the number of MCUs to be filled;
  • the present disclosure also proposes an image repairing device, which includes:
  • a detection unit configured to detect whether a header file of an image to be repaired is damaged, and if so, obtain a correct header file
  • a repairing unit configured to repair the image to be repaired based on the correct header file to obtain a repaired image.
  • the image to be repaired is an image in jpg format.
  • the operation of obtaining the correct header file is: obtaining an intact image of the header file generated by using the same software or equipment as the image to be repaired, and obtaining the header file of the intact image of the header file as the Describes the correct header file for the image to be repaired.
  • the operations performed by the repair unit are:
  • step (1) (4) Decode Cb DC coefficient value and AC coefficient value according to Huffman tree DCT 0 , DCT 1 ACT 0, and ACT 1. If decoding is successful, continue to step (1), if decoding fails, continue to process the next pending in the DS set. Repair the data block and continue with step (1);
  • DcCount> (Width / McuCount) * 3. If yes, it means that a piece of data is pre-decoded. If not, if it is MCULINE, > MCU_MAX, if yes, end the processing, where MCULINE is the number of the data block currently being processed to be repaired, and MCU_MAX is the total number of data blocks to be repaired;
  • DC [i] is an element in the DCF set
  • M is the image width
  • N is the current value of DcCount
  • Average is the smoothness of the image
  • the apparatus further includes:
  • a correction unit is configured to correct position, brightness, and chrominance of the repaired image.
  • N is the number of decoded DC coefficients
  • WIDTH is the width of the image
  • OFFSET is the offset of the elements in the DCF set
  • W_OFFSET (WIDTH-i) / (Hmax * Vmax), where W_OFFSET represents the number of MCUs to be filled;
  • the present disclosure also proposes a computer-readable storage medium on which computer program code is stored, and when the computer program code is executed by a computer, any one of the methods described above is performed.
  • the technical effect of the present disclosure is: The present disclosure solves the technical problem that the image header file is missing and the image cannot be restored by acquiring the complete JPG image header file of the same software or device as the header file for repairing the damaged image. And further determine whether the coding area is covered by other data. If the coding area is covered, the position of the data will be restored, the technical problem of fancy screens in the restored data is solved, and the restoration effect of the image is improved.
  • FIG. 1 is a flowchart of an image repair method according to an embodiment of the present disclosure.
  • FIG. 2 is a structural diagram of an image repair apparatus according to an embodiment of the present disclosure.
  • a JPG (JPEG) file can be roughly divided into two parts: a tag and compressed data.
  • the tag code consists of two bytes. The first byte is a fixed value of 0xFF, and the latter byte has different values according to different meanings.
  • An unlimited number of meaningless 0xFF paddings can be added before each mark code, that is, multiple consecutive 0xFF can be understood as a 0xFF, and the beginning of a mark code.
  • the compressed data stream corresponding to the tag code records all kinds of information about the file. Commonly used tags are SOI, APP0, DQT, SOF0, DHT, DRI, SOS, EOI.
  • the encoding process of JPG is as follows: RGB format image data is preprocessed into YCrCb format through color space conversion. Since the subsequent DCT transformation is to process 8x8 subblocks. Therefore, before performing the DCT transformation, the source image data must be divided into 8 * 8 data blocks, followed by DCT transformation, quantization, encoding, and then reading and processing the next 8 * 8 data block. Important information such as image width and height, sampling ratio, quantization table, and encoding table involved in this entire encoding process are stored in the JPG file header.
  • the decoding process of JPG is the inverse process of JPG encoding.
  • the important information involved in the decoding process comes from the header stored in the JPG file. . Therefore, when a JPG image with a damaged JPG head cannot be decoded, a method based on extracting the complete JPG header information generated by the same software or device to reconstruct the header information of the damaged image for repair is required. This is an important disclosure of the method of the present disclosure.
  • the principle is that the header information (also called header files, header data, etc.) of the JPG image generated by the same software or device is the same, that is, under the same parameters, the same software or device The header information for generating JPG images is consistent.
  • FIGS. 1-2 Detailed description is given below with reference to FIGS. 1-2.
  • FIG. 1 illustrates an image repair method of the present disclosure.
  • the method includes:
  • Detection step S101 detecting whether a header file of an image to be repaired is damaged, and if yes, obtaining a correct header file;
  • a repairing step S102 the image to be repaired is repaired based on a correct header file to obtain a repaired image.
  • This method can repair damaged images in jpg format. Of course, it can also repair other types of images, such as bitmap, tiff and other formats. The principle of repair is the same.
  • An important disclosure point of the present disclosure is to obtain the correct header file.
  • the operation of obtaining the correct header file is to obtain an intact image of the header file generated by using the same software or equipment as the image to be repaired, and obtain the image.
  • the header file of the image whose header file is intact serves as the correct header file of the image to be repaired.
  • the principle is that the header information (also called header files, header data, etc.) of the JPG image generated by the same software or device is the same, that is, the header information of the JPG image generated by the same software or device is the same under the same parameters .
  • the so-called MCU can also be called the data of a square matrix pixel in the image.
  • the size of the matrix is determined as follows: From R 4 of JHD, the sampling factors of different color components of the image, that is, the horizontal sampling factors and vertical sampling factors of the three components of Y, Cr, and Cb, can be obtained. Most pictures have a sampling factor of 4: 1: 1 or 1: 1. Among them, 4: 1: 1: 1 means (2 * 2) :( 1 * 1) :( 1 * 1)); 1: 1: 1 means (1 * 1) :( 1 * 1) (1 * 1).
  • Each DU i represents each data unit.
  • MCUs are arranged from left to right and from top to bottom. Each MCU is divided into several data units. The size of the data unit (DU i ) must be 8 * 8.
  • repair step S102 Another important disclosure of the present disclosure is how to perform image repair.
  • the operation of the repair step S102 is:
  • DS ⁇ M 1 , M 2 , M 3 , ..., M N ⁇ represents a set of minimum coding units. Wherein each element M i representative of each coding unit.
  • MCU minimum coding unit
  • the minimum coding unit (MCU) data stream can be divided into segments. Each MCU is divided into several data unit records. So the data stream information can be analyzed as follows: data stream - > minimum coding unit - > data unit and color component.
  • Y 1 , Cr 1 , and Cb 1 are a color component unit. Among them, Y indicates a luminance signal, and Cr and Cb indicate a chrominance signal. Within each MCU, the order of data is Y, Cr, and Cb. Because the image data stream stores information in units of bits.
  • the internal data are all obtained by transforming the space-time domain to the frequency domain through forward discrete cosine transform (FDCT) during encoding, so for each color component unit, it should be composed of two parts: 1 DC component and 63 An AC component, which is also a DUi. There is a strong correlation between the DC component DC values of adjacent Y luminance component units.
  • FDCT forward discrete cosine transform
  • the decoding process is actually a Huffman tree lookup process, where the DC component of the Y component corresponds to the Huffman tree DCT 0 and the AC component corresponds to the Huffman tree ACT 0 ; the DC component of the Cr component corresponds to the Huffman tree DCT 1 , AC component corresponds to Huffman tree ACT 1 ; DC component of Cb component corresponds to Huffman tree DCT 1 , and AC component corresponds to Huffman tree ACT 1.
  • the DC variables of two adjacent color component units are encoded by difference. That is, the value of the DC variable decoded is only the actual DC variable of the current color component unit minus the actual DC variable of the previous color component unit. That is, the current DC variable is corrected by the actual (non-decoded) DC component of the previous color component unit:
  • Diff is the differential correction variable, which is the DC coefficient directly decoded. But if the current color component unit is the first unit, the decoded DC value is the real DC variable.
  • DcCount> (Width / McuCount) * 3. If yes, it means that a piece of data is pre-decoded. If not, if it is MCULINE, > MCU_MAX, if yes, end the processing, where MCULINE is the number of the data block currently being processed to be repaired, and MCU_MAX is the total number of data blocks to be repaired;
  • DC [i] is an element in the DCF set
  • M is the image width
  • N is the current value of DcCount
  • Average is the smoothness of the image
  • the method further includes: a correction step S103, which corrects position, brightness, and chrominance of the repaired image.
  • the operation of the correction step S103 is:
  • N is the number of decoded DC coefficients
  • WIDTH is the width of the image
  • OFFSET is the offset of the elements in the DCF set
  • W_OFFSET (WIDTH-i) / (Hmax * Vmax), where W_OFFSET represents the number of MCUs to be filled;
  • the method shown in Figure 1 solves the technical problem that the image header file is missing and the image cannot be restored, and further determines whether any coding area is covered by other data. If the coding area is covered, the position of the data will be restored, and the restoration is solved. After the data there are technical problems of Huaping.
  • FIG. 2 illustrates an image repair apparatus according to the present disclosure.
  • the apparatus includes:
  • a detecting unit 201 configured to detect whether a header file of an image to be repaired is damaged, and if yes, obtain a correct header file
  • the repairing unit 202 is configured to repair the image to be repaired based on a correct header file to obtain a repaired image.
  • This device can repair damaged images in jpg format, of course, it can also repair other types of images, such as bitmap, tiff and other formats. The principle of repair is the same.
  • An important disclosure point of the present disclosure is to obtain the correct header file.
  • the operation of obtaining the correct header file is to obtain an intact image of the header file generated by using the same software or equipment as the image to be repaired, and obtain the image.
  • the header file of the image whose header file is intact serves as the correct header file of the image to be repaired.
  • the principle is that the header information (also called header files, header data, etc.) of the JPG image generated by the same software or device is the same, that is, the header information of the JPG image generated by the same software or device is the same under the same parameters .
  • the so-called MCU can also be called the data of a square matrix pixel in the image.
  • the size of the matrix is determined as follows: From R 4 of JHD, the sampling factors of different color components of the image, that is, the horizontal sampling factors and vertical sampling factors of the three components of Y, Cr, and Cb, can be obtained. Most pictures have a sampling factor of 4: 1: 1 or 1: 1. Among them, 4: 1: 1: 1 means (2 * 2) :( 1 * 1) :( 1 * 1)); 1: 1: 1 means (1 * 1) :( 1 * 1) (1 * 1).
  • Each DU i represents each data unit. In the data flow, the arrangement of MCUs is from left to right and from top to bottom, and each MCU is divided into several data units. The size of the data unit (DU i ) must be 8 * 8.
  • repair unit 202 Another important disclosure of the present disclosure is how to perform image repair.
  • the operations performed by the repair unit 202 are:
  • DS ⁇ M 1 , M 2 , M 3 , ..., M N ⁇ represents a set of minimum coding units. Wherein each element M i representative of each coding unit.
  • MCU minimum coding unit
  • the minimum coding unit (MCU) data stream can be divided into segments. Each MCU is divided into several data unit records. So the data stream information can be analyzed as follows: data stream - > minimum coding unit - > data unit and color component.
  • step (1) (4) Decode Cb DC coefficient value and AC coefficient value according to Huffman tree DCT 0 , DCT 1 ACT 0, and ACT 1. If decoding is successful, continue to step (1), if decoding fails, continue to process the next pending in the DS set. Repair the data block and continue with step (1).
  • Y 1 , Cr 1 , and Cb 1 are a color component unit.
  • Y indicates a luminance signal
  • Cr and Cb indicate a chrominance signal.
  • the order of data is Y, Cr, and Cb. Because the image data stream stores information in units of bits.
  • the internal data are all obtained by transforming the space-time domain to the frequency domain through forward discrete cosine transform (FDCT) during encoding, so for each color component unit, it should be composed of two parts: 1 DC component and 63 An AC component, which is also a DUi. There is a strong correlation between the DC component DC values of adjacent Y luminance component units.
  • FDCT forward discrete cosine transform
  • the decoding process is actually a Huffman tree lookup process, where the DC component of the Y component corresponds to the Huffman tree DCT 0 and the AC component corresponds to the Huffman tree ACT 0 ; the DC component of the Cr component corresponds to the Huffman tree DCT 1 , AC component corresponds to Huffman tree ACT 1 ; DC component of Cb component corresponds to Huffman tree DCT 1 , and AC component corresponds to Huffman tree ACT 1.
  • the DC variables of two adjacent color component units are encoded by difference. That is, the value of the DC variable decoded is only the actual DC variable of the current color component unit minus the actual DC variable of the previous color component unit. That is, the current DC variable is corrected by the actual (non-decoded) DC component of the previous color component unit:
  • Diff is the differential correction variable, which is the DC coefficient directly decoded. But if the current color component unit is the first unit, the decoded DC value is the real DC variable.
  • DcCount> (Width / McuCount) * 3. If yes, it means that a piece of data is pre-decoded. If not, if it is MCULINE > MCU_MAX, if yes, end the processing, where MCULINE is the number of the data block currently being processed to be repaired, and MCU_MAX is the total number of data blocks to be repaired;
  • DC [i] is an element in the DCF set
  • M is the image width
  • N is the current value of DcCount
  • Average is the smoothness of the image
  • the device further includes:
  • the correction unit 203 corrects the position, brightness, and chroma of the restored image.
  • the operations performed by the correction unit 203 are:
  • N is the number of decoded DC coefficients
  • WIDTH is the width of the image
  • OFFSET is the offset of the elements in the DCF set
  • W_OFFSET (WIDTH-i) / (Hmax * Vmax), where W_OFFSET represents the number of MCUs to be filled;
  • the device shown in FIG. 2 solves the technical problem that the image header file is missing and cannot restore the image, and further determines whether any coding area is covered by other data. If the coding area is covered, the position of the data will be restored and the restoration After the data there are technical problems of Huaping.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Signal Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

公开了一种图像修复方法、装置及存储介质,该方法包括:检测步骤,检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;修复步骤,基于正确的头文件对所述待修复图像进行修复,得到修复后的图像;校正步骤,对所述修复后的图像进行位置、亮度和色度的校正。本公开通过获取相同软件或者设备生成JPG图像完整头部文件作为修复受损图片的头部文件进行图像的修复,解决了图像头部文件缺失而无法恢复图像的技术问题,并进一步判断是否有编码区被其他数据覆盖,如果有编码区被覆盖,将进行数据的位置恢复,解决了恢复后的数据存在花屏的技术问题,提高了图像的恢复效果。

Description

一种图像修复方法、装置及存储介质
相关申请
本申请要求保护在2018年8月10日提交的申请号为201810907619.9的中国专利申请的优先权,该申请的全部内容以引用的方式结合到本文中。
技术领域
本公开涉及图像处理技术领域,特别是一种图像修复方法、装置及存储介质。
背景技术
JPG做为一种图像格式,由于其高效的压缩效率和标准化要求,JPG图像已广泛用于彩色传真、手机存储,相机存储、电话会议、电商及新闻图像的传送上。因此,对于JPG图像恢复技术在计算机安全领域中一直是备受关注的热点。目前传统的数据恢复软件对于受损的图像,特别是头部缺失的图像修复率往往比较低。
JPG的数据恢复技术受到了广泛的关注和研究。现有的JPG文件恢复技术,都是通过签名恢复的方式或者基于文件系统的碎片重组方式恢复出相关的文件而对于头部签名缺失的JPG文件则无能为力。
现有的JPG文件恢复技术都是通过解析基于文件系统的碎片重组或者签名恢复的方式实现的,对于编码区被其他数据覆盖则会出现打开的文件出现画面花屏无法观看的情况。
公开内容
本公开针对上述现有技术中的缺陷,提出了如下技术方案。
一种图像修复方法,该方法包括:
检测步骤,检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
修复步骤,基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
更进一步地,所述待修复图像是jpg格式的图像。
更进一步地,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。
更进一步地,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼 树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
更进一步地,所述修复步骤的操作为:
(1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS;
(2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量;
(3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
(4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
(5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
(6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
Figure PCTCN2019099119-appb-000001
Figure PCTCN2019099119-appb-000002
其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
(7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
(8)把Average加入DF集合,然后记为
Figure PCTCN2019099119-appb-000003
并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1) 继续处理。
更进一步地,所述方法还包括:
校正步骤,对所述修复后的图像进行位置、亮度和色度的校正。
更进一步地,所述校正步骤的操作为:
(1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
(2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
(3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
(4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
Figure PCTCN2019099119-appb-000004
其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
(5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax*Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
(6)对需要填充的MCU进行编码填充。
本公开还提出了一种图像修复装置,该装置包括:
检测单元,用于检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
修复单元,用于基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
更进一步地,所述待修复图像是jpg格式的图像。
更进一步地,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。
更进一步地,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈 夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
更进一步地,所述修复单元执行的操作为:
(1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS;
(2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量;
(3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
(4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
(5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
(6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
Figure PCTCN2019099119-appb-000005
Figure PCTCN2019099119-appb-000006
其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
(7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
(8)把Average加入DF集合,然后记为
Figure PCTCN2019099119-appb-000007
并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到 此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1)继续处理。
更进一步地,所述装置还包括:
校正单元,用于对所述修复后的图像进行位置、亮度和色度的校正。
更进一步地,所述校正单元执行的操作为:
(1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
(2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
(3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
(4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
Figure PCTCN2019099119-appb-000008
其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
(5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax*Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
(6)对需要填充的MCU进行编码填充。
本公开还提出了一种计算机可读存储介质,所述存储介质上存储有计算机程序代码,当所述计算机程序代码被计算机执行时执行上述之任一的方法。
本公开的技术效果为:本公开通过获取相同软件或者设备生成JPG图像完整头部文件作为修复受损图片的头部文件进行图像的修复,解决了图像头部文件缺失而无法恢复图像的技术问题,并进一步判断是否有编码区被其他数据覆盖,如果有编码区被覆盖,将进行数据的位置恢复,解决了恢复后的数据存在花屏的技术问题,提高了图像的恢复效果。
附图说明
图1是根据本公开的实施例的一种图像修复方法的流程图。
图2是根据本公开的实施例的一种图像修复装置的结构图。
具体实施方式
JPG(JPEG)文件大体上可以分成两个部分:标记码(Tag)和压缩数据。标记码由两个字节构成,其前一个字节是固定值0xFF,后一个字节则根据不同意义有不同数值。在每个标记码之前还可以添加数目不限的无意义的0xFF填充,也就说连续的多个0xFF可以被理解为一个0xFF,并表示一个标记码的开始。而在一个完整的两字节的标记码后,就是该标记码对应的压缩数据流,记录了关于文件的诸种信息。常用的标记有SOI、APP0、DQT、SOF0、 DHT、DRI、SOS、EOI。
JPG的编码流程如下:RGB格式的图像数据经过颜色空间转换预处理成YCrCb格式,由于后面的DCT变换是是对8x8的子块进行处理的。因此,在进行DCT变换之前必须把源图象数据分割成8*8的数据块,接着进行DCT变换,量化,编码,然后再读取、处理下一个8*8的数据块。这一整个编码流程涉及到的图像宽高、采样比、量化表、编码表等重要信息都存储在JPG的文件头部。而JPG的解码流程则是JPG编码的逆过程,其解码过程涉及到的重要信息(如:图像宽高、哈夫曼编码表、抽样因子、量化表等)都来自存储在JPG文件的头部。因此,当JPG头部受损JPG图像无法解码的时候,就需要采用基于提取相同软件或者设备生成JPG完整头部信息来重构受损图片的头部信息进行修复的方法。这是本公开方法的重要公开点,其原理是相同软件或者设备生成JPG图像的头部信息(也称为头文件、头数据等等)是相同的,即在相同参数下,相同软件或者设备生成JPG图像的头部信息是一致的。
下面结合附图1-2进行具体说明。
图1示出了本公开的一种图像修复方法,该方法包括:
检测步骤S101,检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
修复步骤S102,基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
本方法可以对jpg格式的损坏图像进行修复,当然也可以对其他类型的图像进行修复,如位图、tiff等格式的图像,其修复的原理是相同的。
本公开的一个重要公开点是获取正确的头文件,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。其原理是相同软件或者设备生成JPG图像的头部信息(也称为头文件、头数据等等)是相同的,即在相同参数下,相同软件或者设备生成JPG图像的头部信息是一致的。
在本公开的方法中,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
所谓MCU,也可以称为图像中一个正方矩阵像素的数据。矩阵的大小是这样确定的:从 JHD的R 4中可以得到图像不同颜色分量的采样因子,即Y、Cr、Cb三个分量各自的水平采样因子和垂直采样因子。大多图片的采样因子为4:1:1或1:1:1。其中,4:1:1即(2*2):(1*1):(1*1));1:1:1即(1*1):(1*1)(1*1)。记三个分量中水平采样因子最大值为Hmax,垂直采样因子最大值为Vmax,那么单个MCU矩阵的宽就是Hmax*8像素,高就是Vmax*8像素;假设Mi={DU 1,DU 2,DU 3,…DU N}表示数据单元的集合。其中每个DU i代表每个数据单元。在数据流中,MCU的排列方法是从左到右,从上到下,每个MCU又分为若干个数据单元。数据单元(DU i)的大小必定为8*8。
本公开的另一个重要公开点是如何进行图像的修复,所述修复步骤S102的操作为:
(1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS。DS={M 1,M 2,M 3,…,M N}表示最小编码单元的集合。其中每个元素M i代表每个编码单元。对于数据流信息可以被分为一段接一段的最小编码单元(MCU)数据流。而每个MCU又被分成若干个数据单元记。所以数据流信息可以剖析为如下所述:数据流﹣﹥最小编码单元﹣﹥数据单元与颜色分量。
(2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量。
(3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1)。
(4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1)。即Y 1、Cr 1、Cb 1是一个颜色分量单元。其中Y表示亮度信号,Cr和Cb表示色度信号,每个MCU内部,数据的顺序是Y、Cr、Cb。因为图像数据流是以位(bit)为单位存储信息的。并且内部的数据都是在编码时通过正向离散余弦变换(FDCT)进行时空域向频率域变换而得到的结果,所以对于每个颜色分量单元都应该由两部分组成:1个直流分量和63个交流分量,也就是一个DUi。其中相邻Y亮度分量单元的直流分量DC值之间具备很强的关联性。
解码的过程其实就是哈夫曼树的查找过程,其中Y分量的直流分量对应于哈夫曼树DCT 0,交流分量对应于哈夫曼树ACT 0;Cr分量的直流分量对应于哈夫曼树DCT 1,交流分量对应于哈夫曼树ACT 1;Cb分量的直流分量对应于哈夫曼树DCT 1,交流分量对应于哈夫曼树ACT 1。
对于所有的颜色分量单元按颜色分量(Y、Cr、Cb)分类。每一种颜色分量内,相邻的两个颜色分量单元的直流变量是以差分来编码的。也就是说,通过解码出来的直流变量数值只是当前颜色分量单元的实际直流变量减去前一个颜色分量单元的实际直流变量。也就是说,当前直流变量要通过前一个颜色分量单元的实际(非解码)直流分量来校正:
DCi=DCi-1+Diff
其中Diff为差分校正变量,也就是直接解码出来的直流系数。但如果当前颜色分量单元是第一个单元,则解码出来的直流数值就是真正的直流变量。
(5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
(6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
Figure PCTCN2019099119-appb-000009
Figure PCTCN2019099119-appb-000010
其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
(7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
(8)把Average加入DF集合,然后记为
Figure PCTCN2019099119-appb-000011
并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1)继续处理,其中,DA={A 1,A 2,A 3,…,A N}为相邻JPG图像行数之间的平滑度集合。
本公开的另一个重要公开点在于对修复后额图像进行校正,即对数据库被其他数据进行覆盖的部分进行修复,并对色彩进行校正,使得修复后的图像更加逼真,提高了修复效果。如图1所示,所述方法还包括:校正步骤S103,对所述修复后的图像进行位置、亮度和色度的校正。所述校正步骤S103的操作为:
(1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
(2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
(3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
(4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
Figure PCTCN2019099119-appb-000012
其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
(5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax*Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
(6)对需要填充的MCU进行编码填充。
图1所示的方法解决了图像头部文件缺失而无法恢复图像的技术问题,并进一步判断是否有编码区被其他数据覆盖,如果有编码区被覆盖,将进行数据的位置恢复,解决了恢复后的数据存在花屏的技术问题。
图2示出了本公开的一种图像修复装置,该装置包括:
检测单元201,用于检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
修复单元202,用于基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
本装置可以对jpg格式的损坏图像进行修复,当然也可以对其他类型的图像进行修复,如位图、tiff等格式的图像,其修复的原理是相同的。
本公开的一个重要公开点是获取正确的头文件,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。其原理是相同软件或者设备生成JPG图像的头部信息(也称为头文件、头数据等等)是相同的,即在相同参数下,相同软件或者设备生成JPG图像的头部信息是一致的。
在本公开的装置中,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至 HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
所谓MCU,也可以称为图像中一个正方矩阵像素的数据。矩阵的大小是这样确定的:从JHD的R 4中可以得到图像不同颜色分量的采样因子,即Y、Cr、Cb三个分量各自的水平采样因子和垂直采样因子。大多图片的采样因子为4:1:1或1:1:1。其中,4:1:1即(2*2):(1*1):(1*1));1:1:1即(1*1):(1*1)(1*1)。记三个分量中水平采样因子最大值为Hmax,垂直采样因子最大值为Vmax,那么单个MCU矩阵的宽就是Hmax*8像素,高就是Vmax*8像素;假设Mi={DU 1,DU 2,DU 3,…DU N}表示数据单元的集合。其中每个DU i代表每个数据单元。在数据流中,MCU的排列装置是从左到右,从上到下,每个MCU又分为若干个数据单元。数据单元(DU i)的大小必定为8*8。
本公开的另一个重要公开点是如何进行图像的修复,所述修复单元202执行的操作为:
(1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS。DS={M 1,M 2,M 3,…,M N}表示最小编码单元的集合。其中每个元素M i代表每个编码单元。对于数据流信息可以被分为一段接一段的最小编码单元(MCU)数据流。而每个MCU又被分成若干个数据单元记。所以数据流信息可以剖析为如下所述:数据流﹣﹥最小编码单元﹣﹥数据单元与颜色分量。
(2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量。
(3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1)。
(4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续 步骤(1)。
即Y 1、Cr 1、Cb 1是一个颜色分量单元。其中Y表示亮度信号,Cr和Cb表示色度信号,每个MCU内部,数据的顺序是Y、Cr、Cb。因为图像数据流是以位(bit)为单位存储信息的。并且内部的数据都是在编码时通过正向离散余弦变换(FDCT)进行时空域向频率域变换而得到的结果,所以对于每个颜色分量单元都应该由两部分组成:1个直流分量和63个交流分量,也就是一个DUi。其中相邻Y亮度分量单元的直流分量DC值之间具备很强的关联性。
解码的过程其实就是哈夫曼树的查找过程,其中Y分量的直流分量对应于哈夫曼树DCT 0,交流分量对应于哈夫曼树ACT 0;Cr分量的直流分量对应于哈夫曼树DCT 1,交流分量对应于哈夫曼树ACT 1;Cb分量的直流分量对应于哈夫曼树DCT 1,交流分量对应于哈夫曼树ACT 1。
对于所有的颜色分量单元按颜色分量(Y、Cr、Cb)分类。每一种颜色分量内,相邻的两个颜色分量单元的直流变量是以差分来编码的。也就是说,通过解码出来的直流变量数值只是当前颜色分量单元的实际直流变量减去前一个颜色分量单元的实际直流变量。也就是说,当前直流变量要通过前一个颜色分量单元的实际(非解码)直流分量来校正:
DCi=DCi-1+Diff
其中Diff为差分校正变量,也就是直接解码出来的直流系数。但如果当前颜色分量单元是第一个单元,则解码出来的直流数值就是真正的直流变量。
(5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
(6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
Figure PCTCN2019099119-appb-000013
Figure PCTCN2019099119-appb-000014
其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
(7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
(8)把Average加入DF集合,然后记为
Figure PCTCN2019099119-appb-000015
并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1)继续处理,其中,DA={A 1,A 2,A 3,…,A N}为相邻JPG图像行数之间的平滑度集合。
本公开的另一个重要公开点在于对修复后额图像进行校正,即对数据库被其他数据进行覆盖的部分进行修复,并对色彩进行校正,使得修复后的图像更加逼真,提高了修复效果。所述装置还包括:
校正单元203,对所述修复后的图像进行位置、亮度和色度的校正。所述校正单元203执行的操作为:
(1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
(2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
(3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
(4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
Figure PCTCN2019099119-appb-000016
其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
(5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax*Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
(6)对需要填充的MCU进行编码填充。
图2所示的装置解决了图像头部文件缺失而无法恢复图像的技术问题,并进一步判断是否有编码区被其他数据覆盖,如果有编码区被覆盖,将进行数据的位置恢复,解决了恢复后的数据存在花屏的技术问题。
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本申请时可以把各单元的功能在同一个或多个软件和/或硬件中实现。
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以 是个人计算机,服务器,或者网络设备等)执行本申请各个实施例或者实施例的某些部分所述的方法。
最后所应说明的是:以上实施例仅以说明而非限制本公开的技术方案,尽管参照上述实施例对本公开进行了详细说明,本领域的普通技术人员应当理解:依然可以对本公开进行修改或者等同替换,而不脱离本公开的精神和范围的任何修改或局部替换,其均应涵盖在本公开的权利要求范围当中。

Claims (15)

  1. 一种图像修复方法,其特征在于,该方法包括:
    检测步骤,检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
    修复步骤,基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
  2. 根据权利要求1所述的方法,其特征在于,所述待修复图像是jpg格式的图像。
  3. 根据权利要求2所述的方法,其特征在于,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。
  4. 根据权利要求3所述的方法,其特征在于,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
  5. 根据权利要求4所述的方法,其特征在于,所述修复步骤的操作为:
    (1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS;
    (2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量;
    (3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
    (4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
    (5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
    (6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
    Figure PCTCN2019099119-appb-100001
    Figure PCTCN2019099119-appb-100002
    其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
    (7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
    (8)把Average加入DF集合,然后记为
    Figure PCTCN2019099119-appb-100003
    并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1)继续处理。
  6. 根据权利要求5所述的方法,其特征在于,所述方法还包括:
    校正步骤,对所述修复后的图像进行位置、亮度和色度的校正。
  7. 根据权利要求6所述的方法,其特征在于,所述校正步骤的操作为:
    (1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
    (2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
    (3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
    (4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
    Figure PCTCN2019099119-appb-100004
    其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
    (5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax*Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
    (6)对需要填充的MCU进行编码填充。
  8. 一种图像修复装置,其特征在于,该装置包括:
    检测单元,检测待修复图像的头文件是否受损,如果是,则获取正确的头文件;
    修复单元,基于正确的头文件对所述待修复图像进行修复,得到修复后的图像。
  9. 根据权利要求8所述的装置,其特征在于,所述待修复图像是jpg格式的图像。
  10. 根据权利要求9所述的装置,其特征在于,所述获取正确的头文件的操作为:获取与所述待修复图像使用相同软件或设备生成的一幅头文件完好的图像,获取所述头文件完好的图像的头文件作为所述待修复图像的正确的头文件。
  11. 根据权利要求10所述的装置,其特征在于,将所述头文件表示为JHD={R 1,R 2,R 3,R 4,R 5,R 6,R 7},每个元素R i代表头文件的一个字段,从R 1到R 7字段分别表示为:图像开始、应用程序保留标记、定义量化表、帧图像开始、定义哈夫曼表、定义差分编码累计复位的间隔、扫描开始;从R 5的字段中提取哈夫曼表,记为DHT={HT 1,HT 2,HT 3,HT 4}表示哈夫曼编码表集合,HT 1至HT 4分别表示为:表示DC直流0号哈夫曼表、DC直流1号哈夫曼表、AC交流0号哈夫曼表、AC交流1号哈夫曼表;通过HT 1哈夫曼表其构建的哈夫曼树为DCT 0,通过HT 2哈夫曼表构建出哈夫曼树为DCT 1,通过HT 3哈夫曼表构建出哈夫曼树为ACT 0,通过HT 4哈夫曼表构建出哈夫曼树为ACT 1;从R 4字段中解析出颜色分量的采样因子的最大值(Hmax,Vmax)和图片的宽Width和高Hight,根据采样因子最大值(Hmax,Vmax)计算出MCU的大小McuCount=Hmax*Vmax,MCU为所述待修复图像中最小编码单元。
  12. 根据权利要求11所述的装置,其特征在于,所述修复单元执行的操作为:
    (1)加载待修复图像的数据,读取需要修复的数据块并将其作为待解码的数据流DS;
    (2)按照Y->Cr->Cb的流程先解码Y颜色分量,根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Y的直流系数DC值和交流系数值,如果解码成功则存储直流系数DCi值到DCF集合中,同时DcCount累加1,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1),其中,DCF={DC 1,DC 2,DC 3,…,DC N}为Y颜色分量的直流分量的集合,DCi表示一个Y颜色分量的直流分量;
    (3)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cr的直流系数值和交流系数值,如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续步骤(1);
    (4)根据哈夫曼树DCT 0、DCT 1ACT 0和ACT 1解码Cb直流系数值和交流系数值如果解码成功则继续步骤(1),如果解码失败则继续处理DS集合中的下一个待修复的数据块并继续 步骤(1);
    (5)如果连续解码成功一系列的待修复的数据块后则判断是否DcCount>=(Width/McuCount)*3,如果是,则表示预解码出了一段数据,如果否,则如果判断是否MCULINE>MCU_MAX,如果是,则结束处理,其中MCULINE为当前处理的待修复的数据块的编号,MCU_MAX为待修复的数据块的总数目;
    (6)通过集合DCF计算相邻数据块直流值之间的连续性,计算公式如下
    Figure PCTCN2019099119-appb-100005
    Figure PCTCN2019099119-appb-100006
    其中DC[i]为DCF集合中的元素,M为图像宽度,N为DcCount的当前值,Average表示图像的平滑度;
    (7)判断Average>360是否成立,如果是,则此段数据为无效编码数据;如果否,计算DF集合的平滑度,其中DF={D 1,D 2,D 3…,D N},D i代表每行图像的平滑度;
    (8)把Average加入DF集合,然后记为
    Figure PCTCN2019099119-appb-100007
    并判断|DA[i]-DA[i-1]|>7是否成立,如果是,则表示数据块之间存在跃变截止到此则DA[i]部分数据无效,处理结束,如果否,则为数据块为有效编码,跳转到步骤(1)继续处理。
  13. 根据权利要求12所述的装置,其特征在于,所述装置还包括:
    校正单元,用于对所述修复后的图像进行位置、亮度和色度的校正。
  14. 根据权利要求13所述的装置,其特征在于,所述校正单元执行的操作为:
    (1)初始化设置Y分量亮度直流系数DC值,调整图像的亮度;
    (2)初始化设置Cr分量色度直流系数DC值,调整图像色度;
    (3)初始化设置Cb分量色度直流系数DC值,调整图像色度;
    (4)如果图像的画面出现错位偏移,则估算需要填充的MCU的个数,计算出相邻列DC差值的平均值集合,记为DW={W 1,W 2,W 3,…,W N},计算公式如下所示:
    Figure PCTCN2019099119-appb-100008
    其中N表示解码出的DC直流系数的个数,WIDTH表示图像的宽度,OFFSET表示DCF集合中元素的偏移;
    (5)计算出集合DW中最大值Wi,然后根据公式W_OFFSET=(WIDTH-i)/(Hmax* Vmax)计算出需要填充的MCU个数,其中,W_OFFSET表示需要填充的MCU个数;
    (6)对需要填充的MCU进行编码填充。
  15. 一种计算机可读存储介质,其特征在于,所述存储介质上存储有计算机程序代码,当所述计算机程序代码被计算机执行时执行权利要求1-7之任一的方法。
PCT/CN2019/099119 2018-08-10 2019-08-02 一种图像修复方法、装置及存储介质 WO2020029895A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810907619.9 2018-08-10
CN201810907619.9A CN108961193B (zh) 2018-08-10 2018-08-10 一种图像修复方法、装置及存储介质

Publications (1)

Publication Number Publication Date
WO2020029895A1 true WO2020029895A1 (zh) 2020-02-13

Family

ID=64468725

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/099119 WO2020029895A1 (zh) 2018-08-10 2019-08-02 一种图像修复方法、装置及存储介质

Country Status (2)

Country Link
CN (1) CN108961193B (zh)
WO (1) WO2020029895A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113676187A (zh) * 2021-08-11 2021-11-19 山东云海国创云计算装备产业创新中心有限公司 一种哈夫曼修正编码方法、系统及相关组件

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108961193B (zh) * 2018-08-10 2021-04-02 厦门市美亚柏科信息股份有限公司 一种图像修复方法、装置及存储介质
CN111223154B (zh) * 2019-11-20 2022-12-06 厦门市美亚柏科信息股份有限公司 一种jpg图片碎片重组方法、终端设备及存储介质
CN111028135B (zh) * 2019-12-10 2023-06-02 国网重庆市电力公司电力科学研究院 一种图像文件修复方法
CN112215775B (zh) * 2020-10-20 2022-09-06 厦门市美亚柏科信息股份有限公司 一种bmp图片修复方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1670767A (zh) * 2005-04-14 2005-09-21 上海交通大学 图像文件修复方法
CN104200444A (zh) * 2014-09-25 2014-12-10 西北民族大学 基于对称样本块的图像修复方法
US20180220118A1 (en) * 2010-10-06 2018-08-02 Verint Americas Inc. Systems, methods, and software for improved video data recovery effectiveness
CN108961193A (zh) * 2018-08-10 2018-12-07 厦门市美亚柏科信息股份有限公司 一种图像修复方法、装置及存储介质

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP6451102B2 (ja) * 2014-07-03 2019-01-16 大日本印刷株式会社 動画修復装置、動画修復方法、および、動画修復装置用のプログラム
CN107241597B (zh) * 2017-05-05 2019-10-15 中国人民武装警察部队工程大学 一种结合四叉树自适应编码的可逆信息隐藏方法
CN108093299B (zh) * 2017-12-22 2020-08-04 厦门市美亚柏科信息股份有限公司 Mp4损坏文件的修复方法及存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1670767A (zh) * 2005-04-14 2005-09-21 上海交通大学 图像文件修复方法
US20180220118A1 (en) * 2010-10-06 2018-08-02 Verint Americas Inc. Systems, methods, and software for improved video data recovery effectiveness
CN104200444A (zh) * 2014-09-25 2014-12-10 西北民族大学 基于对称样本块的图像修复方法
CN108961193A (zh) * 2018-08-10 2018-12-07 厦门市美亚柏科信息股份有限公司 一种图像修复方法、装置及存储介质

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
HUANG, LI: "The research on header missing JPEG file recovery", ELECTRONIC TECHNOLOGY & INFORMATION SCIENCE, CHINA MASTER'S THESES FULL-TEXT DATABASE, vol. 6, 15 June 2013 (2013-06-15) *
LI, M.: "Research on JPEG Digital Image carving technology in Digital Forensics", ELETRONIC TECHNOLOGY & INFORMATION SCIENCE, CHINA MASTER'S THESES FULL-TEXT DATABASE, vol. 2, 15 February 2018 (2018-02-15) *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113676187A (zh) * 2021-08-11 2021-11-19 山东云海国创云计算装备产业创新中心有限公司 一种哈夫曼修正编码方法、系统及相关组件

Also Published As

Publication number Publication date
CN108961193B (zh) 2021-04-02
CN108961193A (zh) 2018-12-07

Similar Documents

Publication Publication Date Title
WO2020029895A1 (zh) 一种图像修复方法、装置及存储介质
US6285775B1 (en) Watermarking scheme for image authentication
US8977048B2 (en) Method medium system encoding and/or decoding an image using image slices
US7903888B2 (en) Image encoding apparatus and image decoding apparatus
US7630512B2 (en) Method for performing recoverable video and image watermarking which survives block-based video and image compression
US8213727B2 (en) Image encoding apparatus and image decoding apparatus, and control method thereof
CN107087184B (zh) 一种多媒体数据再压缩方法
US20130114687A1 (en) Fixed intra run-level mode for cavlc in hevc
JP4902569B2 (ja) 画像符号化装置及びその制御方法
EP2145480A2 (en) Decoder for selectively decoding predetermined data units from a coded bit stream
CN112468715A (zh) 一种视频追溯系统及视频追溯方法
CN116228507B (zh) 一种数字文本水印溯源方法及系统
US20110299767A1 (en) Image processing apparatus and image processing method
CN112672164A (zh) 视频压缩系统及方法、视频解压缩系统及方法
CN107193838A (zh) 一种自动化检验jpeg图片是否正常的方法
CN106658022B (zh) 一种基于mpeg视频压缩域的完整性水印嵌入与检测方法
JP4037336B2 (ja) 画像処理装置および方法並びにプログラム
JP4757172B2 (ja) 画像符号化装置及びその制御方法
TWI835236B (zh) 影像處理方法及影像處理裝置
JP2004193882A (ja) 画像処理装置、画像データ処理方法、および記録媒体
JPH0879754A (ja) 画像符号化装置及び画像復号化装置
WO1999033275A1 (en) Partial decoding of compressed video sequences
JP4078136B2 (ja) 画像認識方法、画像認識装置及びコンピュータプログラム
CN118118687A (zh) 一种用于视频防篡改的特征提取和比对方法
Zhang et al. H. 264 based screen content coding with HSV quantization

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19847053

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19847053

Country of ref document: EP

Kind code of ref document: A1