I have an image size 300x300. And to faster computation time, I use downsampling it by
I=imresize(originalImage,0.5);
After that, I want to recover it
outputImage=imresize(I,2);
But I see that output image does not simlilar with original image. Which is best way to up and down sampling in matlab? It will return smallest error between original image and output image (after down and up sampling Thank you so much
If you don't need mathematical certainty and just want a heuristic, downsampling is faster and upsampling is more accurate.
Downsampling is the reduction in spatial resolution while keeping the same two-dimensional (2D) representa- tion. It is typically used to reduce the storage and/or transmission requirements of images. Upsampling is the increasing of the spatial resolution while keeping the 2D representation of an image.
Downsampling an image When data is removed the image also degrades to some extent, although not nearly as much as when you upsample. By removing this extra data ( downsampling) this results in a much smaller file size. For example, you can see below that our original image was 17.2 MB at 3000 by 2000 pixels.
You should not expect to recover the larger image exactly. If this were possible, we could losslessly compress images by storing downsampled images and the upscaling them. However, some information is lost when the image is downsample which simply cannot be recovered. If you need to downsample the image for runtime reasons, make sure to keep a copy of the original image if needed. The matlab imresize function provides a number of ways to perform interpolations. It's possible to test the error resulting from a downsample/upsample operation for a particular kernel:
I = int8(imread('rice.png'));
J = imresize(imresize(I,0.5,'box'),2,'box');
mean(abs(J(:) - I(:)))
Running this code with different kernel types yields:
box
4.132904052734375
triangle
4.843124389648438
cubic
4.094940185546875
lanczos2
4.088195800781250
lanczos3
3.948623657226562
Lanczos3 seems to have the smallest error for this image, which isn't too surprising. It's also likely to be the slowest.
If you are focused on the special case of downsampling by half (and up sampling by 2), use impyramid
:
I1 = impyramid(I0, 'reduce');
Ix = impyramid(I1, 'expand');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With