Interpolating a zoomed in colorscale image in Matlab

In summary, the original image is not clear and the clearer image is displayed when individual channels are displayed as 2D matrices.
  • #1
RMZ
29
0
I have no idea what I am doing wrong. I have already found multiple places on the internet which give clear examples of how to do this, yet I am still struggling. Please help me out, or at least point me somewhere. My code is below. I am trying to interpolate pixels of a full color image. The only issue I am having is to display the final 3D matrix representing (what should be) a much clearer version of the original low quality image. During my troubleshooting, I tried displaying individual channels, yet was unable to (almost the entire image shows up as either red, green, or blue depending on which channel I attempted to display). However, displaying individual channels as 2D matrices (e.g. imagesc(newData(:, :, 1)) ) works albeit with an odd set of colors. I have verified in my workspace that the image pixels are being interpolated properly. The image I have been working with is attached.

function I am = displayRGB(filename)
%obtain original picture and zoomed picture information
imData = imread(filename);
zoomData = imData(200:300,200:300,:);

%creating a grid corresponding to existing pixel values, as
% well as for pixel values to be interpolated
[height,width,dimension] = size(imData);
X = 1:width;
Y = 1:height;
[X0,Y0] = meshgrid(X,Y);
[X1,Y1] = meshgrid(200:.25:300,200:.25:300);

%interpolate each channel
newData = zeros(401,401,3);
newData(:,:,1) = interp2(X0,Y0,double(imData(:,:,1)),X1,Y1,'cubic');
newData(:,:,2) = interp2(X0,Y0,double(imData(:,:,2)),X1,Y1,'cubic');
newData(:,:,3) = interp2(X0,Y0,double(imData(:,:,3)),X1,Y1,'cubic');

%display the image
figure; imagesc(zoomData) %original zoomed image
figure; imagesc(newData) %clearer image
 

Attachments

  • lab7_3.jpg
    lab7_3.jpg
    64.1 KB · Views: 571
Last edited:
Physics news on Phys.org
  • #2
Found it... apparently I needed to use newData = uint8(newData) before doing imagesc(newData). Not sure why at the moment (I had already tried using floor and ceiling functions to change the newData array values to integers).
 
  • #3
You could cast it to uin8 but you don't need to if you don't want to. You can use colormaps with floating point arrays. Just use

Code:
imshow(yourDoubleArray, []);
colormap(jet(256)); % Or whatever colormap you want
colorbar;

You can mess around with caxis() if you want to apply the colormap to only a certain range of your data.
 

1. How do I interpolate a zoomed in colorscale image in Matlab?

To interpolate a zoomed in colorscale image in Matlab, you can use the built-in function interp2. This function interpolates an image using bilinear interpolation, which uses nearby pixels to estimate the values of the zoomed in pixels.

2. What is the purpose of interpolating a zoomed in colorscale image?

The purpose of interpolating a zoomed in colorscale image is to improve the visual quality of the image by filling in the gaps between pixels and creating a smoother transition between colors. This can be especially useful when zooming in on an image to avoid pixelation.

3. Can I specify the interpolation method in Matlab?

Yes, you can specify the interpolation method in Matlab by using the optional argument method in the interp2 function. The default method is bilinear interpolation, but you can also choose to use nearest neighbor, bicubic, or spline interpolation.

4. What happens if I try to interpolate an image with missing data?

If you try to interpolate an image with missing data, Matlab will replace the missing values with NaN (not a number) in the interpolated image. It is important to ensure that your image does not have any missing data before interpolating.

5. Is it possible to interpolate a zoomed in colorscale image in Matlab without using the interp2 function?

Yes, it is possible to interpolate a zoomed in colorscale image in Matlab without using the interp2 function. However, this would require writing your own custom code for interpolation, which may not be as efficient or accurate as using the built-in function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
Back
Top