Image Processing - Bilinear Interpolation

بزرگنمایی تصاویر به روش درون یابی Bilinear

در این روش ارزش یک پیکسل بر اساس چهار پیکسل در جهت های عمودی افقی تصویر تعیین می شود، تصویر در این روش تقریبا شطرنجی نمیشود و خاصیت Anti-aliasing دارد

Normal Image: 256 * 256 Pixel

Zoom 2X: 512 * 512 Pixel

Zoom 4X: 1024 * 1024 Pixel

سورس کد

<?php
    $zoom
=$_GET["zoom"];
    
    
$img=imagecreatefrompng("3.png");
    
    
$width imagesx($img);
    
$height imagesy($img);
    
    
$width2 $width $zoom;
    
$height2 $height $zoom;
    
    
$img2=imagecreate($width2,$height2);
    
//imagecolorallocate($img2,0,0,255);
    
    
for($i=0;$i<$width$i++)
    {
        
$check=false;
        for(
$j=0;$j<$height$j++)
        {
            
            
$colorAimagecolorat($img$i$j);
            
$color_arrA=imagecolorsforindex($img$colorA);
            
            @
$colorBimagecolorat($img$i+1$j);
            
$color_arrB=imagecolorsforindex($img$colorB);
            
            @
$colorCimagecolorat($img$i$j+1);
            
$color_arrC=imagecolorsforindex($img$colorC);

            @
$colorDimagecolorat($img$i+1$j+1);
            
$color_arrD=imagecolorsforindex($img$colorD);
            
            
            
            
$color_arr["red"] = floor(($color_arrA["red"] + $color_arrB["red"] + $color_arrC["red"]+ $color_arrD["red"])/4);
            
            
$color_arr["green"] = floor(($color_arrA["green"] + $color_arrB["green"] + $color_arrC["green"]+ $color_arrD["green"])/4);
            
            
$color_arr["blue"] = floor(($color_arrA["blue"] + $color_arrB["blue"] + $color_arrC["blue"]+ $color_arrD["blue"])/4);

            
            for(
$m=0;$m<$zoom$m++)
            {
                for(
$n=0;$n<$zoom$n++)
                {
                    if(
$check==true)
                    {
                        
set_color($img2$i*$zoom+$m$j*$zoom+$n$color_arr);
                        
                    }
                    else 
                    {    
                        
$check=true;
                        
                        
                    }
                    
                    
                }
            }
            
            

                
            
//imagecopyresized($img2,$img, $i*$zoom, $j*$zoom, $i, $j, $zoom, $zoom, 1, 1);
        
}
        
    }
    
    
header("Content-type: image/png");
    
imagepng($img2);
    
imagedestroy($img2);
    
imagedestroy($img);
    
    function 
set_color($img2$i,$j$color_arr)
    {
        
            
        
$color2 imagecolorexact($img2,  $color_arr["red"],$color_arr["green"],$color_arr["blue"]);
            
        if(
$color2==-1
        {
            if(
imagecolorstotal($img2)>=255) {
                
$color2 imagecolorclosest($img2$color_arr["red"],$color_arr["green"],$color_arr["blue"]);
            } 
            else 
            {
                
$color2 imagecolorallocate($img2$color_arr["red"],$color_arr["green"],$color_arr["blue"]);
            }
            
        }
        
        
imagesetpixel($img2,$i,$j,$color2);
        
        
    }
1