필터 지우기
필터 지우기

How do I map the data using interp1()?

조회 수: 1 (최근 30일)
Avinash Bhatt
Avinash Bhatt 2019년 5월 6일
편집: Avinash Bhatt 2019년 5월 13일
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
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
Rik 2019년 5월 7일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
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
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.
Avinash Bhatt
Avinash Bhatt 2019년 5월 13일
편집: Avinash Bhatt 2019년 5월 13일
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.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by