0

I am subsampling an image using matlab. But I have a task to reset the subsampled image to original size. I have done it with nearest neighbour approximation and averaging adjacent pixels which is working fine.Is there any other algorithm to do this?

Thanks in advance.

indu
  • 177
  • 2
  • 11

3 Answers3

3

If you insist on not using the imresize builtin function, you can use interp2 to rescale the image. First define a scaling factor f. Then you can use interp2 to do it as follows.

% Toy Data
I = im2double( imread( 'bag.png' ) );

% Set Scaling Factor
f = 1/5;

% Resize Image
D = interp2( I, linspace( 1, size(I,2), size(I,2) * f ), linspace( 1, size(I,1), size(I,1) * f )' );

% Plot Image
figure; imshow( I );
figure; imshow( D );

To understand what this code does, first understand that this line finds the number of subdivisions within the linspace.

size(I,2) * f 

After you create the linspace, you can use interp2 for the cols for the 2nd argument and rows for the 3rd argument. The image must be a double hence the im2double.

If you don't wish to use interp2 either, as @rayryeng said, you should refer to how to do it without any builtin functions here.

Community
  • 1
  • 1
krisdestruction
  • 1,950
  • 1
  • 10
  • 20
  • While this technically uses inbuild functions for interpolation, I'd assume it would qualify unless doing the interpolation itself was the task. Note that [interp2](http://de.mathworks.com/help/matlab/ref/interp2.html) also features multiple interpolation methods: 'linear', 'nearest', 'cubic' and 'spline'. – Mathias Apr 21 '15 at 08:45
  • @Mathias I agree and its pretty difficult to code your own like that. I changed my answer to specify which built in function wasn't used. While `interp2` does have multiple interpolation methods, this will allow the user to choose which one they want and defaults to (iirc) the linear one. – krisdestruction Apr 21 '15 at 08:55
  • @Mathias also I don't believe that `interp2` requires any toolbox while `imresize` requires the image toolbox which is probably what the OP likely meant – krisdestruction Apr 21 '15 at 08:58
  • @krisdestruction - You can code bilinear interpolation without `interp2` and it's quite simple. See here: http://stackoverflow.com/questions/26142288/resize-an-image-with-bilinear-interpolation-without-imresize – rayryeng Apr 21 '15 at 15:27
  • 1
    @rayryeng Good point, I will add that to my answer. Thanks! – krisdestruction Apr 21 '15 at 17:54
1

What you want is a basic Image resize correct? There are several algorithms available with description from mathworks.

Mathias
  • 1,470
  • 10
  • 20
  • Hi Thank you for the reference. But I should not use matlab inbuilt function. – indu Apr 21 '15 at 08:12
  • 2
    There are like a million resize algorithms. The most popular are Nearest Neighbour, Bilinear, Bicubic, Lanczos and Spline types. The basic is usually generating a picewise interpolation of the pixes and sampling them into a new grid. I'd advise just searching for these algorithms and maybe post a new question, based on that. – Mathias Apr 21 '15 at 08:30
1

yeah, there still have least two method:

  1. pixel area re-sampling
  2. bicubic interpolation
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – sina72 Apr 21 '15 at 10:08
  • maybe this is too short? – an unique monkey Apr 21 '15 at 10:38
  • I did Bicubic Interpolation and the output was what I expected.Thank you. – indu Apr 22 '15 at 09:01
  • This is a ridiculously poor answer, especially when you have one here that actually shows an implementation in MATLAB. https://stackoverflow.com/questions/29765714/resize-an-image-to-original-size-after-sub-sampling/29766889# – rayryeng Jun 01 '20 at 19:32