procedure BoxDownSampling(Image: TImage32; newWidth, newHeight: Integer);
As the name implies, BoxDownSampling is only intended for image down-sampling (ie shrinking images) where it avoids the pixelation produced with other resamplers. However, while BoxDownSampling avoids pixelation, it does tend toward undue blurring. Also, because BoxDownSampling is inferior to other resamplers when performing other transformations (ie when enlarging, rotating, and skewing images), it's not intended as a general purpose resampler.
|Original image (512 x 512px)|
|Bicubic downsampling: note pixelation
The original image was resized to 1/4 its original size using bicubic resampling and then reenlarged back to the original size (again using bicubic resampling) so the results of downsampling can be more easily seen.
|BoxDownSampling: note mild blurring
The original image was resized to 1/4 its original size using the BoxDownSampling function and then reenlarged to the original size (using bicubic resampling) so the results of downsampling can be more easily seen.
uses Img32, Img32.Fmt.PNG, Img32.Extra, Img32.Resamplers; ... var img, img2, img3: TImage32; rec, rec2, rec3: TRect; const scale = 0.25; invScale = 1/scale; begin img := TImage32.Create; img2 := TImage32.Create; img3 := TImage32.Create; try //Bicubic downsampling img.LoadFromFile('fruit.png'); img.Resampler := rBicubicResampler; img.Scale(scale); //BoxDownSampling img2.LoadFromFile('fruit.png'); BoxDownSampling(img2, Round(img2.Width * scale), Round(img2.Height * scale)); //Merge (average) the two images above img3.Assign(img); img3.CopyBlend(img2, img2.Bounds, img3.Bounds, BlendAverage); //make them all bigger again //so we can see the results img.Scale(invScale); img.SaveToFile('bicubic.png'); img2.Scale(invScale); img2.SaveToFile('box.png'); img3.Scale(invScale); img3.SaveToFile('merged.png'); finally img.free; img2.free; img3.free; end; end;
Copyright ©2019 Angus Johnson - Image32 ver. 3.2 - Documentation last updated on 15-September-2021