xsharp.eu • Fabpaint... CropBorders type functionaltiy, does it exist or alternative
Page 1 of 1

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Posted: Wed Oct 07, 2020 1:06 am
by Sherlock
Fabrice.. hello, long time.

I have some images a lot of images that have large strip of white left and right of image content. What to strip this out and even option if there was White space at the top of image. Using say Ifranview there is a menu option called "Crop borders" which does want I want. Really would like this in Fabpaint so I can automate and resize the image.

Imagine image size which includes 3 CM of white space right and left and 1 CM on the top.

HELP...

Phil

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Posted: Wed Oct 07, 2020 12:43 pm
by Fabrice
Hi Phil,
nice to hear from you ! :)

Mmmm, I sure we could do it : Converting the CM to pixels might be the only problem, but based on the dpi, it should be ok.
I will check and come back

Fab

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Posted: Wed Oct 07, 2020 3:27 pm
by Sherlock
Found some code / technique if this helps. I can see the concept but not see in Fabpaint to work at a pixel level.
Thanks Fabrice..

private static BufferedImage autoCrop(BufferedImage sourceImage) {
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
boolean firstFind = true;
for (int x = 0; x < sourceImage.getWidth(); x++) {
for (int y = 0; y < sourceImage.getWidth(); y++) {
// pixel is not empty
if (sourceImage.getRGB(x, y) != 0) {

// we walk from left to right, thus x can be applied as left on first finding
if (firstFind) {
left = x;
}

// update right on each finding, because x can grow only
right = x;

// on first find apply y as top
if (firstFind) {
top = y;
} else {
// on each further find apply y to top only if a lower has been found
top = Math.min(top, y);
}

// on first find apply y as bottom
if (bottom == 0) {
bottom = y;
} else {
// on each further find apply y to bottom only if a higher has been found
bottom = Math.max(bottom, y);
}
firstFind = false;
}
}
}

return sourceImage.getSubimage(left, top, right - left, bottom - top);
}

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Posted: Wed Oct 07, 2020 9:00 pm
by Fabrice
Phil,
first, don't forget that FabPaint is build on top of the FreeImage library.
You will find in FabPaint an access called BitmapBits wich returns a Ptr.
From there, with the Bitmap type, you can retrieve the pixel and it's color (RGB) :
For a sample, you can get the FreeImage doc, and look at FreeImage_GetBits : This is the function used by the Access.
https://freeimage.sourceforge.io/documentation.html

HTH,
Fab

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Posted: Wed Oct 14, 2020 6:07 am
by AlesS
I developed 2 classes that extend FabPaint ver 3.1.0.5 for VO 28. First, SSResizeOrCropImage, intelligently resizes image into some standard resolution, e.g. 1920 x 1080. If the image has different ratio of width/height, an intelligent cropping is applied. The second class SSAutoCropImage chops off white stripes on the edges of an image, if indeed they are there. I attached the source code (as plain text) of these classes and testing function, also an image on which this has been tested. Feel free to use it. The code may be portable to XSharp.