/*********函数功能:提取AC系数***********************************************************
参数:j_decompress_ptr cinfo为解码对象
jvirt_barray_ptr *coeffs为DCT系数
n:为第几个AC系数。n=1为第一行的第一个系数,n=8为第一列的第一个系数
返回值:反应DC系数的图像指针
******************************************************************************************/
IplImage *extract_ac(j_decompress_ptr cinfo, jvirt_barray_ptr *coeffs, int n)
{
jpeg_component_info *ci_ptr = &cinfo->comp_info[0];//第ci通道
CvSize size = cvSize(ci_ptr->width_in_blocks, ci_ptr->height_in_blocks);//定义DC图像的大小
IplImage *dc = cvCreateImage(size, IPL_DEPTH_8U, 1);//建立一个图像
assert(dc != NULL);
JQUANT_TBL *tbl = ci_ptr->quant_table;
UINT16 dc_quant = tbl->quantval[n];//quantval[DCTSIZE2]是量化系数,quantval[1]为AC1的量化系数,量化表的
#if DEBUG
printf("DCT method: %x\n", cinfo->dct_method);
printf
(
"component: %d (%d x %d blocks) sampling: (%d x %d)\n",
ci,
ci_ptr->width_in_blocks,
ci_ptr->height_in_blocks,
ci_ptr->h_samp_factor,
ci_ptr->v_samp_factor
);
printf("quantization table: %d\n", ci);//输出CI通道的量化表
for (int i = 0; i < DCTSIZE2; ++i)
{
printf("% 4d ", (int)(tbl->quantval[i]));
if ((i + 1) % 8 == 0)
printf("\n");
}
printf("raw DC coefficients:\n");//输出ci通道的DC系数
#endif
JBLOCKARRAY buf =
(cinfo->mem->access_virt_barray)
(
(j_common_ptr)cinfo,
coeffs[0],
0,
ci_ptr->v_samp_factor,
FALSE
);
for (int sf = 0; (JDIMENSION)sf < ci_ptr->height_in_blocks; ++sf)
{
for (JDIMENSION b = 0; b < ci_ptr->width_in_blocks; ++b)
{
int intensity = 0;
intensity = buf[sf][b][n]*dc_quant/DC_SIZE + 128;
intensity = MAX(0, intensity);
intensity = MIN(255, intensity);
cvSet2D(dc, sf, (int)b, cvScalar(intensity));//为DC的下标为(sf,b)的元素赋值
#if DEBUG
printf("% 2d ", buf[sf][b][n]);
#endif
}
#if DEBUG
printf("\n");
#endif
}
return dc;
}
1 个解决方案
#1
| Y | | 0.299 0.587 0.114 | | R | | 0 |
| Cb | = |- 0.1687 - 0.3313 0.5 | * | G | + |128|
| Cr | | 0.5 - 0.4187 - 0.0813| | B | |128|
#1
| Y | | 0.299 0.587 0.114 | | R | | 0 |
| Cb | = |- 0.1687 - 0.3313 0.5 | * | G | + |128|
| Cr | | 0.5 - 0.4187 - 0.0813| | B | |128|