resample an image from pixel to millimiters

2019-08-05 04:56发布

问题:

I have an image (logical values), like this

I need to get this image resampled from pixel to mm or cm; this is the code I use to get the resampling:

function [ Ires ] = imresample3( I, pixDim )

    [r,c]=size(I);
    x=1:1:c;
    y=1:1:r;
    [X,Y]=meshgrid(x,y);

    rn=r*pixDim;
    cn=c*pixDim;
    xNew=1:pixDim:cn;
    yNew=1:pixDim:rn;
    [Xnew,Ynew]=meshgrid(xNew,yNew);

    Id=double(I);

    Ires=interp2(X,Y,Id,Xnew,Ynew);

end

What I get is a black image. I suspect that this code does something that is not what I have in mind: it seems to take only the upper-left part of the image.

What I want is, instead, to have the same image on a mm/cm scale: what I expect is that every white pixel should be mapped from the original position to the new position (in mm/cm); what happen is certainly not what I expect.

I'm not sure that interp2 is the right command to use.

I don't want to resize the image, I just want to go from pixel world to mm/cm world.

pixDim is of course the dimension of the image pixel, obtained dividing the height of the ear in cm by the height of the ear in mm (and it is on average 0.019 cm).

Any ideas?

EDIT: I was quite sure that the code had no sense, but someone told me to do that way...anyway, if I have two edged ears, I need first to scale both the the real dimension and then perform some operations on them. What I mean with "real dimension" is that if one has size 6.5x3.5cm and the other has size 6x3.2cm, I need to perform operations on this dimensions. I don't get how can I move from the pixel dimension to cm dimension BEFORE doing operation. I want to move from one world to the other because I want to get rid of the capturing distance (because I suppose that if a picture of the ear is taken near and the other is taken far, they should have different size in pixel dimension). Am I correct? There is a way to do it? I thought I can plot the ear scaling the axis, but then I suppose I cannot subtract one from the other, right?

回答1:

Matlab does not use units. To apply your factor of 0.019cm/pixel you have to scale by a factor of 0.019 to have a 1cm grid, but this would cause any artefact below a size of 1cm to be lost.

Best practice is to display the data using multiple axis, one for cm and one for pixels. It's explained here: http://www.mathworks.de/de/help/matlab/creating_plots/using-multiple-x-and-y-axes.html

Any function processing the data should be independent of the scale or use the scale factor as an input argument, everything else is a sign of some serious algorithmic issues.