如何在Matlab中拉伸图像

时间:2011-06-02 09:59:58

标签: matlab image-processing

所有

我需要知道如何拉伸图像以进行进一步的工作。

例如,我有接下来的两张图片:

enter image description here enter image description here

我希望数字会像这样填满整个广场:

enter image description here enter image description here

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

假设背景是一个常量值,并且图像没有任何常量行,cols,并且有用图像是带有背景的较大图像中间的矩形:

colsWithImg = find(any(abs(diff(img)))); % idxs of cols with any img in it.
rowsWithImg = find(any(abs(diff(img'))));
imgWithNoBG = img(min(rowsWithImg):max(rowsWithImg),min(colsWithImg):max(colsWithImg));
% this will also work: but you will lose any constant rows / cols
% imgWithNoBG = img(rowsWithImg,colsWithImg);

现在你的图像没有背景,只要你有图像处理工具箱就很容易使用imresize进行拉伸。

resizedImg = imrezize(imgWithNoBG,newSize);

要删除工件,首先要对提取的字符进行描述:

descImg = floor((nDescLevels*imgWithNoBg)/max(max(imgWithNoBg)))
colsNoArtifact = find(any(abs(diff(descImg))));
rowsNoArtifact = find(any(abs(diff(descImg'))));

然后从非descritized图像中提取正确的行

img3 = imgWithNoBG(min(rowsNoArtifact):max(rowsNoArtifact),min(colsNoArtifact):max(colsNoArtifact));

降低descritization级别的数量将有助于删除更多的工件,但会使其更有可能错误地删除部分字符。我还想象一些像1或7这样的数字的问题,其中部分角色可能被误认为是神器。

答案 1 :(得分:0)

图像的背景是黑色的?白色? 找到包围图像的最小矩形。并通过命令img切割边框(uppixel:downpoxil,leftpixel:rightpixel)

您可以通过for循环找到最小的矩形,并将不在背景中的每个像素与边框进行比较