You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
i cant use interpolation in matlab
3 views (last 30 days)
Show older comments
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
Accepted Answer
Chandra
on 5 Apr 2022
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 Comments
ibrahim çömez
on 18 Apr 2022
i cannot find the value of v can you help me ? thank you for answer
Chandra
on 19 Apr 2022
"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);
Walter Roberson
on 22 Apr 2022
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
on 22 Apr 2022
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
on 25 Apr 2022
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.
ibrahim çömez
on 25 Apr 2022
image-pro can you contact me we have a same problem and we can together solve it.
ibrahim çömez
on 25 Apr 2022
@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
on 25 Apr 2022
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
image-pro
on 26 Apr 2022
ibrahim çömez you have any idea how to solve this problem?
Walter Roberson
on 26 Apr 2022
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
on 26 Apr 2022
- 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
on 26 Apr 2022
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
on 26 Apr 2022
@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
on 26 Apr 2022
surf() is only for surfaces, not for volumes. For volumes use volumeViewer() or slice() or isosurface()
Chandra
on 27 Apr 2022
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
on 27 Apr 2022
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
on 28 Apr 2022
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,[]);
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)
Asia-Pacifico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)