How do I map the data using interp1()?

3 views (last 30 days)
Avinash Bhatt
Avinash Bhatt on 6 May 2019
Edited: Avinash Bhatt on 13 May 2019
I am mapping the data using interp1(). The code is not working, please help me to solve this issue
clc
clear all
close all
x=imread('cameraman.tif');
[r c]=size(x);
[ri ci]=imhist(x);
for i=1:r
for j=1:c
z=x(i,j);
end
end
a=interp1(ci,ri,z,'cubic');
plot(a);
  6 Comments
Rik
Rik on 7 May 2019
What do you mean by mapping? What are you trying to do with the histogram? The function you're using only works for a one dimensional input.
Rik
Rik on 7 May 2019
Comment posted as answer by Avinash Bhatt moved here
Sir,
I mean to say I want to map the image pixels(x-axis) to the frequency of image image pixels(y-axis) on histogtam of image and I am trying to map the image data using cubic spline interpolation on histogram therefore I am using interp1().
The image attached clearly dipicts which I ma trying to do.

Sign in to comment.

Answers (1)

Rik
Rik on 7 May 2019
I have no clue why you would want to do this, but the code below will treat the histogram as a lookup table. You need to convert the image to a vector of double type for this to work, and picking a good normalization to get back to grayscale might be tricky, but you should be able to edit this code.
x=imread('cameraman.tif');
[counts,centers]=imhist(x);
x2=interp1(centers,counts,double(x(:)));
x2=reshape(x2,size(x));%note x2 is a double, not uint8
figure(1),clf(1)%use clf only during debuggin
imshow(x2,[])
  5 Comments
Rik
Rik on 13 May 2019
This is a really strange way to threshold an image. You need to do a lot of assumptions about your input before you can do a reasonable fit and determine a reasonable threshold value from that fit. I can't really get it to work with fit, even with this image (cameraman.tif), which contains two distinct groups of intensity levels. You need to assume the order of the polynomial you want to fit, as well as the number of pieces. If your initial guesses are too far off, you have no hope of getting a reasonable fit, and there is no real way to predict the initial guesses without first performing the thresholding operation in a more reasonable way.
If this is homework I would ask your instructor for advice on how to proceed, otherwise I would suggest rethinking this strategy.
Avinash Bhatt
Avinash Bhatt on 13 May 2019
Edited: Avinash Bhatt on 13 May 2019
Sir,
I have compressed the image to 16X16, will it work with this kind of image.
Please suggest me some modifications I can perform in it.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!