How do I map the data using interp1()?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2019-5-7
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
2019-5-7
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.
回答(1 个)
Rik
2019-5-7
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 个评论
Rik
2019-5-13
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!