0

I added a .JPG file to Matlab workspace, Matlab loaded it as a 2D array of 300x300 unsigned integers in range 0-255. I am interested in analyzing one of the rows of this matrix. For that purpose I simply extracted the row using

row = ones(300);
row = myMatrix(150, :);

Then, I realized that in order to compare it with another array, which is of length 450 elements, I need to expand my row vector by a factor of 1.5, i.e. stretch my array to 450 samples. For that purpose, I tried using resample function as follows :

row2 = resample(row, 3, 2);

But I received error saying that resample function does not support data of unit8 type.

Is there a way to achieve interpolation using resample in my case, or would you recommend another approach?

The Vivandiere
  • 3,059
  • 3
  • 28
  • 50

1 Answers1

1

I think you have to convert image to double when you read it:

imgOriginal = imread('FileName.jpg');
imgDbl = double( imgOriginal );
% if you need you may also convert the image to [0..1] range
% imgDbl = double( imgOriginal ) / double( intmax(class(imgOriginal)) );

For resizing it is better to use imresize:

imgResized = imresize( imgDbl , 1.5, 'bilinear' ); % use the method you need

because for interpolating methods it will take into account rows above/below the one you need. Then you may select the right row

row = imgResized(150,:);
rayryeng
  • 102,964
  • 22
  • 184
  • 193
anandr
  • 1,622
  • 1
  • 12
  • 10
  • Resample gives error with double as well, says double not a supported type – The Vivandiere Sep 04 '14 at 22:31
  • @user3670482 Do you have a variable called `resample` in your workspace? This sounds like a potential variable shadowing. Try doing `clear resample`, then try your code again with the image being casted as `double`. BTW, I would also suggest you use `imresize`. This function is built specifically for resizing images. – rayryeng Sep 05 '14 at 00:54