interp3 RGB - temperature
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I would like to write a piece of code which takes the RGB values from a picture and change them in temperature.
I have a calibration file which has for each RGB a temperature. I wanted to use the interp3 to start from the calibration file and go to the new picture.
THe function interp3 gives me an error when I use it, since it says that V (in my case temperature) should be a 3D matrix.
PLease, would you mind helping me or addressing in a different direction.
Thank you very much
Antonio
I attacch my piece of code
%calRGB.txt contains 4 columns: R,G,B,temperature (calibration file)
load calRGB.txt
%RGB_f.dat contains 5 columns, x, y, R, G, B of the picture (2d picture)
load RGB_f.dat
RGB=RGB_f;
x=RGB(:,1);
y=RGB(:,2);
v=RGB(:,3);
w=RGB(:,4);
z=RGB(:,5);
%initialize temp
temp=x;
temp(:)=0;
%interpolation
for ii = 1:length(x(:,1))
temp(ii)=interp3(calRGB(:,1), calRGB(:,2),calRGB(:,3),calRGB(:,4), v(ii),w(ii),z(ii));
end
%write the temperature for each point on a variable
output=RGB_f;
output(:,:,:)=0;
for ii = 1:length(x(:,1))
output(ii,:)=[x(ii), y(ii) ,temp(ii)];
end
0 commentaires
Réponse acceptée
the cyclist
le 31 Mar 2011
Although you can probably get interp3 to work in this case, I think it is preferable to to use the function TriScatteredInterp for this. It is a two-step process, in which you first create the interpolant from the calibration file, then use that interpolant on the data. You also don't need to use the for loops, because the whole thing can be vectorized. I believe that the code below does what you want, but of course you should check:
% calRGB.txt contains 4 columns: R,G,B,temperature (calibration file)
load calRGB.txt
% calRGB = [0 0 0 0; ...
% 0 0 1 1; ...
% 0 1 0 2; ...
% 0 1 1 3; ...
% 1 0 0 4; ...
% 1 0 1 5; ...
% 1 1 0 6; ...
% 1 1 1 7];
% RGB_f.dat contains 5 columns, x, y, R, G, B of the picture (2d picture)
load RGB_f.dat
% RGB_f = [1 1 0.5 0.5 0.5; ...
% 2 2 0.7 0.7 0.7];
RGB=RGB_f;
x=RGB(:,1);
y=RGB(:,2);
v=RGB(:,3);
w=RGB(:,4);
z=RGB(:,5);
temperatureInterpolant = TriScatteredInterp(calRGB(:,1), calRGB(:,2),calRGB(:,3),calRGB(:,4));
output = [x,y,temperatureInterpolant(v,w,z)]
Note that there is also a syntax for calling TriScatteredInterp that does not require you to split up your RGB data into three separate vectors, but I did not want to stray too far from the syntax of your original code.
Hope that helps. [Note that I included (commented out) a very simple example of RGB arrays that worked for me.]
Plus de réponses (2)
mortain Antonio
le 4 Avr 2011
2 commentaires
the cyclist
le 5 Avr 2011
Almost certainly the NaNs are value that lie outside the "convex hull" (the outer boundary) of your known values. You can test this by temporarily choosing "nearest" as the interpolation method for TriScatteredInterp, and seeing if the NaNs go away. My guess is they will.
You can use the CONVHULL command to plot out what your convex hull looks like.
Are you able to extend your grid of known points, to capture those points? If not, you can't really interpolate between.
[Also, you should accept this answer if it was helpful, so that others with a similar question can get the benefit of the answer in the future.]
mortain Antonio
le 5 Avr 2011
1 commentaire
the cyclist
le 5 Avr 2011
When you use the nearest method, you need to enclose that in single quotes: 'nearest'.
The command is lower-case: convhull. "help convhull" for details. (I was using the unfortunate convention from the documentation, in which commands are written in all caps even though that is not how you type them.)
Voir également
Catégories
En savoir plus sur Discrete Data Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!