이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
i cant use interpolation in matlab
조회 수: 5 (최근 30일)
이전 댓글 표시
ibrahim çömez
2022년 3월 30일
I wanted to get the edges of the images and interpolate them to create a 3D image. But interp3 works incorrectly or not at all.
can someone help me? how can I create a 3D image with interpolation?
how can i add interp3 to this code ?
A=imread('1-173Final.png');
C=double(A);
for i=1:size(C,1)-2
for j=1:size(C,2)-2
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
B(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
[x y z] = ind2sub(size(B), find(B));
figure(1)
plot3(x, y, z, 'k.');
P=imread('1-171Final.png');
V=double(P);
for i=1:size(V,1)-2
for j=1:size(V,2)-2
Gx=((2*V(i+2,j+1)+V(i+2,j)+V(i+2,j+2))-(2*V(i,j+1)+V(i,j)+V(i,j+2)));
Gy=((2*V(i+1,j+2)+V(i,j+2)+V(i+2,j+2))-(2*V(i+1,j)+V(i,j)+V(i+2,j)));
L(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
[q w e] = ind2sub(size(L), find(L));
hold on
e=e+0.01;
plot3(q, w, e, 'b.');
hold off
채택된 답변
Chandra
2022년 4월 5일
Hi,
'interp3' expects the x,y,z,v inputs in meshgrid ordering
>> Vq3 = interp3(y,x,z,v,Yq,Xq,Zq); % meshgrid order for X, Y, Z, V
For more information, please refer to the documentation pages:
댓글 수: 22
Chandra
2022년 4월 19일
"v" is the function value of x,y,z and xq,yq and zq are interpolation points.
If "v" need to be interpolated then use "interp3(v)" and corresponding technique for interpolation like "cubic", "Linear" etc... (if v is 3 dimension then it is more productive)
Try combining the two images and then use interp3
A(:,:,1) = B;
A(:,:,2) = L;
interp3(A);
image-pro
2022년 4월 22일
can we use newton divided difference interpolation formula to interpolate image?
Walter Roberson
2022년 4월 22일
Yes, you can do that.
How useful, or accurate, or efficient doing that would be is a different question.
The first step would be to extend the formula from 1 indepedent variable to 2 independent variables. After that you would use the row and column numbers as the y and x coordinates, and the pixel values as the z coordinates, to construct a multinomial of degree ((number of rows) * (number of columns) - 1) and that could then be used for interpolation.
Walter Roberson
2022년 4월 22일
MATLAB is a general-purpose programming language, that can compute anything deterministic that fits within the available memory. You asked whether you can use that technique, not whether it can be done compactly or efficiently, or whether you can achieve useful accuracy in your calculation, and the answer is Yes, it can be done. It might take you several months to write the code, but it can be done.
Is it a good idea? NO.
Newton Divided Difference is mathematically equivalent to creating a lagrange interpolating polynomial. The minimum degree of the interpolating polynomial would be at least one less than the number of pixels. So for a 512 x 512 image, you would be creating a polynomial that is at least total degree 262143 . In practice, once you take an interpolating polynomial beyond degree 7, it starts to become more and more dominated by noise, and degree 10 is about as far as you can go without the results being complete garbage -- at least in double precision.
https://link.springer.com/article/10.1007/BF01386056 gives an analysis of how to create a NDD interpolation in 2D with irregularly spaced values. You do not need that; what you need is the information in the introductory sentence, "Existing bivariate schemes either iterate the one-dimensional scheme" . That tells you that you can use a 1D NDD scheme along each row, and then flip that around and use a 1D NDD scheme along each column. For a 512 x 512 image, that is going to get you a polynomial of degree 511 in each row, interacting with a polynomial of degree 511 for each column. That would seem to give a lower total degree than I indicated earlier (512 x 512 - 1); I cannot account for that at the moment.
Either way, total degree is going to be above 200000, and that is going to give you floating point nonsense unless you use the Symbolic Mathematics Toolbox and operate at something on the order of 3 million digits.
In my opinion, it would be a waste of time to pursue this technique in the form stated.
What might be feasible is to do a NDD interpolation over a very small window, such as 3 x 3. However, you would probably be needing to use a moving-window approach, so any one point would be included in several different interpolation areas. You would have to decide how to select the output from the competing choices. It might, for example, be reasonable to say that in each case you only interpolate for new locations that are "inside" the central pixel of the location you are doing the inteprolation over (and if you did that, you would have to decide how to handle new locations that are exactly on the border between two pixels.)
Walter Roberson
2022년 4월 25일
Send you code to do exactly what ?? What would be the inputs? What would be the expected outputs?
If the requirements are pretty trivial then I might post code... but otherwise I am more likely to tell you to make an attempt and then we would help you debug it.
image-pro
2022년 4월 25일
i have brain tumor image and i want to apply NDD interpolation for reconstruction. Is it possible in matlab?
ibrahim çömez
2022년 4월 25일
image-pro can you contact me we have a same problem and we can together solve it.
ibrahim çömez
2022년 4월 25일
@Mathan Chandran hi mate, i can try to this code but i have a question. A is (512,512) matrix and B is (510,510). this case i cant use interpolate but thanks for everything. just this code and i want to create 3-d a colon. how can it possible can you recommend anything?
Walter Roberson
2022년 4월 25일
Okay, so you have one brain tumour image. Grayscale or RGB ?
What control parameters do you need as input beyond the image itself?
What is the expected output?
"Is it possible in matlab?"
If you are using the entire image to do NDD, then you have a small number of possibilities:
- You could compute a NDD interpolation that is numeric garbage; or
- If your image was in a range of sizes, you might be able to use Symbolic Toolbox to try to compute NDD to acceptable accuracy, only to find that you run out of memory
- If your image is sufficiently large, then you might find that the limitations of the Symbolic do not permit acceptable accuracy (the symbolic toolbox has a limit of roughly
) - If your image is pretty small, you might be able to do something reasonable with the Symbolic Toolbox
- If your image is no larger than 3 x 3, you might be able to do something that is not entirely terrible using double precision
Walter Roberson
2022년 4월 26일
image-pro, it is difficult to assist you when you do not answer questions about what the task is. Just saying that you need to do NDD interpolation on a brain tumour image is not enough.
- is it rgb or grayscale?
- is the information from the entire image to be considered for the interpolation, or are you to work with independent tiles, or do you need to use a sliding window? If you are using tiles or sliding windows then how large?
- is the interpolation to take place at user-specified coordinates, or at a fixed scaling factor, or at a user-specified scaling factor, or should it continue until some criteria is reached?
- what output is required?
image-pro
2022년 4월 26일
- firstly i am using grayscale image.
- only segmented brain tumor image is to be considered for the interpolation.
- on user defined cordinates automatically it pick x and y coordinates.
- lastly, i want value of y when x value is given. i have estimate value of y (effected cell of brain tumor).
i hope you understand my problem.
Walter Roberson
2022년 4월 26일
Sorry, I do not understand about the automatic picking if coordinates.
Brain tumours typically affect multiple cells in any given vertical line, and the affected cells are not necessarily connected.
Do I understand correctly that you will be passing in some kind of label array as well as the image array, with the label array indicating which segment each pixel belongs to?
ibrahim çömez
2022년 4월 26일
@Walter Roberson hi mate, i have a problem.
A=imread('1-173Final.png');
C=double(A);
for i=1:size(C,1)-2
A=imread('1-173Final.png');
C=double(A);
for i=1:size(C,1)-2
for j=1:size(C,2)-2
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
B(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
[x y z] = ind2sub(size(B), find(B));
figure(1)
plot3(x, y, z, 'k.');
P=imread('1-171Final.png');
V=double(P);
for i=1:size(V,1)-2
for j=1:size(V,2)-2
Gx=((2*V(i+2,j+1)+V(i+2,j)+V(i+2,j+2))-(2*V(i,j+1)+V(i,j)+V(i,j+2)));
Gy=((2*V(i+1,j+2)+V(i,j+2)+V(i+2,j+2))-(2*V(i+1,j)+V(i,j)+V(i+2,j)));
L(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
[q w e] = ind2sub(size(L), find(L));
hold on
e=e+0.01;
plot3(q, w, e, 'b.');
hold off
K(:,:,1) = B;
K(:,:,2) = L;
interp3(K);
surf(K);
Error using matlab.graphics.chart.primitive.Surface
Value must be a scalar, vector or array of numeric type.
Error in surf (line 145)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
Error in Untitled (line 30)
surf(K);
what is that i cant understand why this run error. just want to 3-D interpolation and create 3-D colon images.

Walter Roberson
2022년 4월 26일
surf() is only for surfaces, not for volumes. For volumes use volumeViewer() or slice() or isosurface()
Chandra
2022년 4월 27일
Try using,
K = interp3(k);% ensure all values of same class (like double, single etc.)
imshow(K,[]);
The K value has 3 planes, the B image shown in Red, L image shown in Blue and the interpolated values are shown in green (if interpolation is present i.e., mid value of R and L), if there is no difference then grey image is projected.
Walter Roberson
2022년 4월 27일
I am confused about what k (lower-case) is in your suggestion? I do not see a k in the user code? I see a K (capital), but the user K has three panes, and interp3() by default subdivides every dimension once, so interp3() of something N x M x 3 would give a result that is (2*N-1) by (2*M-1) by 5, and you cannot imshow() something that has more than 1 pane.
I do not understand where the 3 color panes you are talking about come from?
Chandra
2022년 4월 28일
Here the images in B and L are considered as a 2D matrix as I assumed from the code mentioned, so after applying the "interp3" the output will be (2*M-1)x(2*N-1)x3, as K is two MxN matrix, here depending on the assigning value we can use k in interp3, if images are assigned to K(capital) then
k = interp3(K); % K capital in interp3 and k small in assigned value
imshow(k,[]);
%OR
K = interp3(K); % K capital in interp3 and k capital in assigned value
imshow(K,[]);
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
