shading17*13

这段代码处理图像数据,将多个图像帧的像素值累加并除以图像总数得到平均值。然后,它将数据分为四个通道,并对每个通道进行块处理,计算每个块的像素平均值,存储在对应的双精度数组中。
摘要由CSDN通过智能技术生成

    if (m_iImageIndex < m_option->m_uImageCount)
    {
        ushort *pusTempImage = (ushort *)image;
        for (int i = 0; i < m_FrameParam.Height * m_FrameParam.Width; i++)
        {
            m_usImage[i] += pusTempImage[i];
        }
        m_iImageIndex++;
        if (m_iImageIndex < m_option->m_uImageCount)
        {
            return ERR_Continue;
        }
    }

    for (int i = 0; i < m_FrameParam.Height * m_FrameParam.Width; i++)
    {
        m_usImage[i] = (m_usImage[i] / m_option->m_uImageCount) & 0xffff;
    }

    int width = m_FrameParam.Width;
    int height = m_FrameParam.Height;
    const int BLC = 64;

    if (0)
    {
        unsigned short *pPixelValue = (unsigned short *)m_usImage;
        // GRBG
        FILE *pfGr = fopen("0_pixel_Gr.csv", "w");
        FILE *pfR = fopen("0_pixel_R.csv", "w");
        FILE *pfB = fopen("0_pixel_B.csv", "w");
        FILE *pfGb = fopen("0_pixel_Gb.csv", "w");

        for (int i = 0; i < height; i += 2)
        {
            for (int j = 0; j < width; j += 2)
            {
                fprintf(pfGr, "%d,", pPixelValue[i * width + j] - BLC);
                fprintf(pfR,  "%d,", pPixelValue[i * width + j + 1] - BLC);
                fprintf(pfB,  "%d,", pPixelValue[(i + 1) * width + j] - BLC);
                fprintf(pfGb, "%d,", pPixelValue[(i + 1) * width + j + 1] - BLC);
            }
            fprintf(pfGr, "\n");
            fprintf(pfR,  "\n");
            fprintf(pfB,  "\n");
            fprintf(pfGb, "\n");
        }

        fclose(pfGr);
        fclose(pfR);
        fclose(pfGb);
        fclose(pfB);
    }

    {
        //4个通道
        int *pChannel1 = new int[width / 2 * height / 2];
        int *pChannel2 = new int[width / 2 * height / 2];
        int *pChannel3 = new int[width / 2 * height / 2];
        int *pChannel4 = new int[width / 2 * height / 2];

        unsigned short *pPixelValue = (unsigned short *)m_usImage;

        int idx = 0;
        for (int i = 0; i < height; i += 2)
        {
            for (int j = 0; j < width; j += 2)
            {
                pChannel1[idx] = pPixelValue[i*width + j] - BLC;
                pChannel2[idx] = pPixelValue[i*width + j + 1] - BLC;
                pChannel3[idx] = pPixelValue[(i + 1)*width + j] - BLC;
                pChannel4[idx] = pPixelValue[(i + 1)*width + j + 1] - BLC;
                idx++;
            }
        }


        {
            int block_w = (width / 2) / 17;
            int block_h = (height / 2) / 13;
            int col_17_block_w = (width / 2) / 17 + (width / 2) % 17;
            int row_13_block_h = (height / 2) / 13 + (height / 2) % 13;

            // row,行;column,列;
            for (size_t r = 0; r < 13; r++)
            {
                for (size_t c = 0; c < 17; c++)
                {
                    int w = (c != 16) ? block_w : col_17_block_w;
                    int h = (r != 12) ? block_h : row_13_block_h;

                    int ichannel_1 = 0, ichannel_2 = 0, ichannel_3 = 0, ichannel_4 = 0;
                    int pixelCount = 0;

                    for (size_t i = 0; i < h; i++)
                    {
                        for (size_t j = 0; j < w; j++)
                        {
                            int x = c * block_w + j;
                            int y = r * block_h + i;
                            int index = y * (width / 2) + x;
                            ichannel_1 += pChannel1[index];
                            ichannel_2 += pChannel2[index];
                            ichannel_3 += pChannel3[index];
                            ichannel_4 += pChannel4[index];
                            pixelCount++;
                        }
                    }

                    m_dChannel_1[r * 17 + c] = (double)ichannel_1 / pixelCount;
                    m_dChannel_2[r * 17 + c] = (double)ichannel_2 / pixelCount;
                    m_dChannel_3[r * 17 + c] = (double)ichannel_3 / pixelCount;
                    m_dChannel_4[r * 17 + c] = (double)ichannel_4 / pixelCount;
                }
            }
        }
    }
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值