DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.76k stars 389 forks source link

I want to use this control to remove the black edge around the image. What should I do? I'll understand it for the first time #590

Open jueqing1015 opened 3 years ago

jueqing1015 commented 3 years ago

I want to use this control to remove the black edge around the image. What should I do? I'll understand it for the first time https://user-images.githubusercontent.com/65677359/131935495-f0d9951e-0111-4e95-8299-62db3475f3ba.jpg

DanBloomberg commented 3 years ago

do you want to fill in the black tears around the edge (with white pixels), so that the text is in a white rectangle with straight edges?

jueqing1015 commented 3 years ago

@DanBloomberg Yes, I need to remove the black areas on the four sides, but the image is RGB However, the background color of the image is not necessarily white, but may also be other colors Just fill the surrounding black areas with white Is there any method? Please give guidance for the first use

DanBloomberg commented 2 years ago

Here's how you do it:

    pixa1 = pixaCreate(4);
    pix1 = pixRead("clean-edges.jpg");
    pixaAddPix(pixa1, pix1, L_COPY);

    // Convert to 1 bpp and remove fg components touching border
    // Result is 1 bpp image with border cleaned up
    pix2 = pixConvertTo1(pix1, 180);
    pix3 = pixRemoveBorderConnComps(pix2, 8);
    pixaAddPix(pixa1, pix3, L_INSERT);

    // If you want the result to be the original image (32 bpp) with
    // border components painted white (0xffffffff), get a mask of
    // the border components and paint through the mask onto the
    // original image
    pix4 = pixXor(NULL, pix2, pix3);
    pixaAddPix(pixa1, pix4, L_INSERT);
    pixPaintThroughMask(pix1, pix4, 0, 0, 0xffffffff);
    pixaAddPix(pixa1, pix1, L_INSERT);

    // Show the results
    pix5 = pixaDisplayTiledInColumns(pixa1, 1, 1.0, 20, 2);
    pixDisplay(pix5, 100, 800);
    pixWrite("/tmp/results.jpg", pix5, IFF_JFIF_JPEG);
DanBloomberg commented 2 years ago

here's the final result; from the top:

results