Objective c 如何在ios sdk中创建1位映像?

Objective c 如何在ios sdk中创建1位映像?,objective-c,ios4,image-processing,uiimageview,Objective C,Ios4,Image Processing,Uiimageview,我想将图像转换为1位图像进行ocr读取。我尝试根据像素的阈值来替换像素,但是结果太暗,黑色,我用C++库来处理< /P> 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 init

我想将图像转换为1位图像进行ocr读取。我尝试根据像素的阈值来替换像素,但是结果太暗,黑色,我用C++库来处理< /P>
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);
}
ImageWrapper*图像::AutoCalThreshold(){
const int local_size=8;
//现在生成阈值图像
uint8_t*结果=(uint8_t*)malloc(m_宽度*m_高度);
//得到最初的总数
int-total=0;

对于(int y=0;yIt),看起来您使用的是自适应阈值。要扩展Randy所说的内容,也许您可以对局部阈值进行调整,使其偏移更高或更低,并更改哪些像素通过阈值。这应该会改变图像的色调。