예제 #1
0
Pix* livreAdapt(Pix* pixs){
    Pix* pixg, *pix1;
    
    /* Normalize for uneven illumination on gray image. */
    pixBackgroundNormGrayArrayMorph(pixs, NULL, 4, 5, 200, &pixg);
    pix1 = pixApplyInvBackgroundGrayMap(pixs, pixg, 4, 4);
    pixDestroy(&pixg);
    
    return pix1;
}
예제 #2
0
/*
 * Binarize and fix uneven illumination
 */
void MainWindow::on_actionBinarizeUnIl_triggered() {
  QApplication::setOverrideCursor(Qt::WaitCursor);
  PIX *pixc, *pixg, *pixsg, *pixd;

  /* Convert the RGB image to grayscale. */
  this->statusBar()->showMessage(tr("Convert the RGB image to grayscale."));
  pixsg = pixConvertRGBToLuminance(pixs);
  setPixToScene(pixsg);

  /* Remove the text in the fg. */
  this->statusBar()->showMessage(tr("Remove the text in the fg."));
  pixc = pixCloseGray(pixsg, 25, 25);
  setPixToScene(pixc);

  /* Smooth the bg with a convolution. */
  // pixsm = pixBlockconv(pixc, 15, 15);
  // pixDestroy(&pixsm);

  /* Normalize for uneven illumination on gray image. */
  this->statusBar()->showMessage(tr("Normalize for uneven illumination on gray image."));
  pixBackgroundNormGrayArrayMorph(pixsg, NULL, 4, 5, 200, &pixg);
  pixc = pixApplyInvBackgroundGrayMap(pixsg, pixg, 4, 4);
  pixDestroy(&pixsg);
  pixDestroy(&pixg);
  setPixToScene(pixc);

  /* Increase the dynamic range. */
  // make dark gray *black* and light gray *white*
  this->statusBar()->showMessage(tr("Increase the dynamic range."));
  pixd = pixGammaTRC(NULL, pixc, 1.0, 50, 220);
  setPixToScene(pixd);

  /* Threshold to 1 bpp. */
  this->statusBar()->showMessage(tr("Threshold to 1 bpp."));
  pixs = pixThresholdToBinary(pixd, 120);
  pixDestroy(&pixd);
  setPixToScene();

  this->statusBar()->showMessage(tr("Finished..."), 2000);
  modified = true;
  updateTitle();
  QApplication::restoreOverrideCursor();
}
예제 #3
0
main(int    argc,
     char **argv)
{
l_int32      d;
PIX         *pixs, *pixc, *pixr, *pixg, *pixb, *pixsg, *pixsm, *pixd;
PIXA        *pixa;
static char  mainName[] = "livre_adapt";

    if (argc != 1)
	exit(ERROR_INT(" Syntax:  livre_adapt", mainName, 1));

        /* Read the image in at 150 ppi. */
    pixDisplayWrite(NULL, -1);
    if ((pixs = pixRead("brothers.150.jpg")) == NULL)
	exit(ERROR_INT("pix not made", mainName, 1));
    pixDisplayWriteFormat(pixs, 2, IFF_JFIF_JPEG);

        /* Normalize for uneven illumination on RGB image */
    pixBackgroundNormRGBArraysMorph(pixs, NULL, 4, 5, 200,
                                    &pixr, &pixg, &pixb);
    pixd = pixApplyInvBackgroundRGBMap(pixs, pixr, pixg, pixb, 4, 4);
    pixDisplayWriteFormat(pixd, 2, IFF_JFIF_JPEG); 
    pixDestroy(&pixr);
    pixDestroy(&pixg);
    pixDestroy(&pixb);
    pixDestroy(&pixd);

        /* Convert the RGB image to grayscale. */
    pixsg = pixConvertRGBToLuminance(pixs);
    pixDisplayWriteFormat(pixsg, 2, IFF_JFIF_JPEG);

        /* Remove the text in the fg. */
    pixc = pixCloseGray(pixsg, 25, 25);
    pixDisplayWriteFormat(pixc, 2, IFF_JFIF_JPEG);

        /* Smooth the bg with a convolution. */
    pixsm = pixBlockconv(pixc, 15, 15);
    pixDisplayWriteFormat(pixsm, 2, IFF_JFIF_JPEG);
    pixDestroy(&pixc);

        /* Normalize for uneven illumination on gray image. */
    pixBackgroundNormGrayArrayMorph(pixsg, NULL, 4, 5, 200, &pixg);
    pixc = pixApplyInvBackgroundGrayMap(pixsg, pixg, 4, 4);
    pixDisplayWriteFormat(pixc, 2, IFF_JFIF_JPEG);
    pixDestroy(&pixg);

        /* Increase the dynamic range. */
    pixd = pixGammaTRC(NULL, pixc, 1.0, 30, 180);
    pixDisplayWriteFormat(pixd, 2, IFF_JFIF_JPEG);
    pixDestroy(&pixc);

        /* Threshold to 1 bpp. */
    pixb = pixThresholdToBinary(pixd, 120);
    pixDisplayWriteFormat(pixb, 2, IFF_PNG);
    pixDestroy(&pixd);
    pixDestroy(&pixb);

            /* Generate the output image */
    pixa = pixaReadFiles("/tmp", "junk_write_display");
    pixd = pixaDisplayTiledAndScaled(pixa, 8, 350, 4, 0, 25, 2);
    pixWrite("/tmp/adapt.jpg", pixd, IFF_JFIF_JPEG);
    pixDisplayWithTitle(pixd, 100, 100, NULL, 1);
    pixDestroy(&pixd);

    pixDestroy(&pixs);
    pixDestroy(&pixsg);
    return 0;
}