将图像从像素重新采样到限制器 [英] resample an image from pixel to millimiters

查看:123
本文介绍了将图像从像素重新采样到限制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片(逻辑值),像这样

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.

我想要的是,以mm/cm的比例显示相同的图像:我希望每个白色像素都应从原始位置映射到新位置(以mm/cm为单位);发生的事情肯定不是我所期望的.

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.

我不确定interp2是正确使用的命令.

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

我不想调整图像大小,我只想从像素世界转到mm/cm世界.

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

pixDim当然是图像像素的尺寸,它是用以厘米为单位的耳朵高度除以以毫米为单位的耳朵高度(平均为0.019厘米)而得到的.

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).

有什么想法吗?

我非常确定代码没有意义,但是有人告诉我要这样做...无论如何,如果我有两只耳朵,我需要先对真实尺寸进行缩放,然后再执行一些操作.对它们的操作.我所说的实际尺寸"是指,如果一个尺寸为6.5x3.5cm,另一个尺寸为6x3.2cm,则需要对此尺寸执行操作. 在执行操作之前,我不知道如何从像素尺寸移动到cm尺寸. 我想从一个世界移到另一个世界,因为我想摆脱捕捉距离(因为我想如果耳朵的照片靠近拍摄而另一个距离很远,则它们在像素尺寸上应该有不同的大小) . 我对么?有办法吗?我以为我可以画出按比例缩放耳朵的耳朵,但是我想我不能从另一个中减去一个,对吧?

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不使用单位.要应用0.019厘米/像素的因子,您必须按0.019比例缩放以具有1厘米的网格,但这会导致丢失任何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.

最佳做法是使用多轴显示数据,其中一个表示厘米,另一个表示像素.此处说明: http://www.mathworks.de/de/help/matlab/creating_plots/using-multiple-x-and-y-axes.html

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.

这篇关于将图像从像素重新采样到限制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆