如何在ios sdk中创建1位图像?

时间:2012-07-06 00:02:26

标签: objective-c ios4 image-processing uiimageview

我想将图像转换为1位图像以进行ocr读取。我试图根据它的阈值替换像素,但结果太暗和黑色我正在使用c ++库

ImageWrapper* Image::autoLocalThreshold() {
    const int local_size=8;
    // now produce the thresholded image
    uint8_t *result=(uint8_t*) malloc(m_width*m_height);
    // get the initial total
    int total=0;
    for(int y=0; y<local_size; y++) {
        for(int x=0; x<local_size; x++) {
            total+=(*this)[y][x];
        }
    }
    // process the image
    int lastIndex=m_width*m_height-(m_width*local_size/2+local_size/2);
    for(int index=m_width*local_size/2+local_size/2; index<lastIndex; index++) {
        int threshold=total/64;
        if(m_imageData[index]>threshold*0.9)
            result[index]=0;
        else
            result[index]=255;
        // calculate the new total
        for(int index2=index-m_width*local_size/2-local_size/2; index2<index+m_width*local_size/2-local_size/2; index2+=m_width) {
            total-=m_imageData[index2];
            total+=m_imageData[index2+local_size];
        }
    }
    return Image::createImage(result, m_width, m_height, true);
}

有人能让我知道如何正确地做到这一点并创建一个1位图像(黑白)图像吗?

提前致谢。我将非常感谢您的帮助

0 个答案:

没有答案