resample an image from pixel to millimiters


I have an image (logical values), like this

<img alt="http://imageshack.com/a/img46/7493/cswr.png" class="b-lazy" data-src="https://i.stack.imgur.com/euzFc.png" data-original="https://i.stack.imgur.com/euzFc.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

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?


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: <a href="http://www.mathworks.de/de/help/matlab/creating_plots/using-multiple-x-and-y-axes.html" rel="nofollow">http://www.mathworks.de/de/help/matlab/creating_plots/using-multiple-x-and-y-axes.html</a>

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.


  • Type mismatch: cannot convert from ListFragment to Fragment
  • replacing while loop with list comprehension
  • CSS Grid, position absolute an element in a css grid item: IMPOSSIBLE
  • How to enable mapping the private property of the entity
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • AlertDialog style when using setView()
  • HTML5 video only works in IE. The other browsers shows the black screen
  • How to split circle in to the sectors in google maps?
  • Which open source license has no forking [closed]
  • WPF version of .ScaleControl?
  • How can I replace the server in Web Component Tester
  • Do query loads all the data in memory
  • blade.php method outputting it's result to the form
  • Who propagate bugfixes across branches (corporate development)?
  • DIV instruction jumping to random location?
  • xcode don't localize specific strings
  • Django model inheritance, filtering models
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • AndEngine Applying Transparancy to AndEngine View
  • D3 get axis values on zoom event
  • Eloquent paginate function in Slim 3 project using twig
  • How integrated is Collada to OpenGL ES
  • Blackberry - Custom EditField Cursor
  • Android fill_parent issue
  • Handling un-mapped Rest path
  • Body moving without any force applied? (Box2d)
  • ilmerge with a PFX file
  • JFileChooser in front of fullscreen Swing application
  • What is Eclipse's Declaration View used for?
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Fill an image in a square container while keeping aspect ratio
  • Jquery - Jquery Wysiwyg return html as a string
  • SVN: Merging two branches together
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Android Google Maps API OnLocationChanged only called once
  • Bitwise OR returns boolean when one of operands is nil
  • Append folder name and increment by 1 using batch script
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Running Map reduces the dimensions of the matrices