Fastest way to scale binary images??
-
Hi, I am looking for a fastest way to scale up/down a binary image. I may end up scaling images only in X direction. Is there any easiest/fastest way to do this in VC++?? For now my images are stored in an array (not a two-dimensional array, but just a single strip array(one row after another from the image). Since I am dealing with binary images, I hope I dont need to use interpolation. The data that I have is the original dimensions of the image and the final dimensions of the image. For example, my original image is 9x9 and my new dimensions are 15x9. thanks, -Pavan.
-
Hi, I am looking for a fastest way to scale up/down a binary image. I may end up scaling images only in X direction. Is there any easiest/fastest way to do this in VC++?? For now my images are stored in an array (not a two-dimensional array, but just a single strip array(one row after another from the image). Since I am dealing with binary images, I hope I dont need to use interpolation. The data that I have is the original dimensions of the image and the final dimensions of the image. For example, my original image is 9x9 and my new dimensions are 15x9. thanks, -Pavan.
if you're not limiting your output size to certain whole multiples of the input size, you're going to have to do some interpolation (if you want reasonable-looking output). but, bi-linear interpolation is pretty easy.
image processing toolkits | batch image processing | blogging
-
if you're not limiting your output size to certain whole multiples of the input size, you're going to have to do some interpolation (if you want reasonable-looking output). but, bi-linear interpolation is pretty easy.
image processing toolkits | batch image processing | blogging
Any articles on bi-linear interpolation that is easy to understand... -Pavan
-
Any articles on bi-linear interpolation that is easy to understand... -Pavan
in 1-D, linear interpolation looks like this:
// ratio of input size to output size
factor1 = inputPoints / outputPoints// loop over output
for (current=0 to outputPoints-1)
{
// center of our input pixel is here. it's probably fractional.
inputPixelLocation = current * factor1// get the two pixels on either side of that center point
input1 = pixel[floor(inputPixelLocation)]
input2 = pixel[floor(inputPixelLocation) + 1]// the fractional part of this tells us how close we are to the left-most source pixel.
factor2 = fractional_part_of(inputPixelLocation)// average of the two pixels, weighted by factor2
output = input1 * factor2 + input2 * (1.0 - factor2)
}in 2D, you pick four pixels: two from the current pixel row (as above) and another two from the row immediately beneath. and then you combine all four with the a two-factor weighted average.
factor1X = inputPointsX / outputPointsX
factor1Y = inputPointsY / outputPointsY// vertical loop
for (currentY=0 to outputPointsY-1)
{
// find the vertical factor
inputPixelLocationY = currentY * factor1Y// horizontal loop
for (currentX=0 to outputPointsX-1)
{
// find horizontal factor
inputPixelLocationX = currentX * factor1XfloorX = floor(inputPixelLocationX) floorY = floor(inputPixelLocationY) // get four pixels: X,Y - X+1,Y - X,Y+1, X+1,Y+1 input1 = pixel\[floorX \]\[floorY\] input2 = pixel\[floorX + 1\]\[floorY\] input3 = pixel\[floorX\]\[floorY + 1\] input4 = pixel\[floorX + 1\]\[floorY + 1\] // two factors factor2X = fractional\_part\_of(inputPixelLocationX) factor2Y = fractional\_part\_of(inputPixelLocationY) factor2X\_inverse = 1.0 - factor2X factor2Y\_inverse = 1.0 - factor2Y // average of the four pixels, weighted by the 2 factor2's outval = input1 \* factor2X \* factor2Y + input2 \* factor2X\_inverse \* factor2Y + input3 \* factor2X \* factor2Y\_inverse + input4 \* factor2X\_inverse \* factor2Y\_inverse output\[currentX\]\[currentY\] = outval
}
}that's a basic bi-lin algorithm. there's a lot of room there for optimization in general, and even more for monochrome data.
image processing toolkits | batch image processing | blogging
-
in 1-D, linear interpolation looks like this:
// ratio of input size to output size
factor1 = inputPoints / outputPoints// loop over output
for (current=0 to outputPoints-1)
{
// center of our input pixel is here. it's probably fractional.
inputPixelLocation = current * factor1// get the two pixels on either side of that center point
input1 = pixel[floor(inputPixelLocation)]
input2 = pixel[floor(inputPixelLocation) + 1]// the fractional part of this tells us how close we are to the left-most source pixel.
factor2 = fractional_part_of(inputPixelLocation)// average of the two pixels, weighted by factor2
output = input1 * factor2 + input2 * (1.0 - factor2)
}in 2D, you pick four pixels: two from the current pixel row (as above) and another two from the row immediately beneath. and then you combine all four with the a two-factor weighted average.
factor1X = inputPointsX / outputPointsX
factor1Y = inputPointsY / outputPointsY// vertical loop
for (currentY=0 to outputPointsY-1)
{
// find the vertical factor
inputPixelLocationY = currentY * factor1Y// horizontal loop
for (currentX=0 to outputPointsX-1)
{
// find horizontal factor
inputPixelLocationX = currentX * factor1XfloorX = floor(inputPixelLocationX) floorY = floor(inputPixelLocationY) // get four pixels: X,Y - X+1,Y - X,Y+1, X+1,Y+1 input1 = pixel\[floorX \]\[floorY\] input2 = pixel\[floorX + 1\]\[floorY\] input3 = pixel\[floorX\]\[floorY + 1\] input4 = pixel\[floorX + 1\]\[floorY + 1\] // two factors factor2X = fractional\_part\_of(inputPixelLocationX) factor2Y = fractional\_part\_of(inputPixelLocationY) factor2X\_inverse = 1.0 - factor2X factor2Y\_inverse = 1.0 - factor2Y // average of the four pixels, weighted by the 2 factor2's outval = input1 \* factor2X \* factor2Y + input2 \* factor2X\_inverse \* factor2Y + input3 \* factor2X \* factor2Y\_inverse + input4 \* factor2X\_inverse \* factor2Y\_inverse output\[currentX\]\[currentY\] = outval
}
}that's a basic bi-lin algorithm. there's a lot of room there for optimization in general, and even more for monochrome data.
image processing toolkits | batch image processing | blogging
Thanks for the info... will try to implement this as easy as I can.. -Pavan.