Matlab imresize功能舍入像素 [英] Matlab imresize function rounding up pixels

查看:259
本文介绍了Matlab imresize功能舍入像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要拍摄162x193像素的图像,基本上将其缩小0.125,即162/8 = 20.25和193/8 = 24.125。因此,我想要一张大小为20x24的图片我目前唯一的问题是,当我使用 imresize 函数时,它会将图像的像素值向上舍入,即我得到一张图像尺寸为21x25而不是20x24。任何获得20x24的方式或者这个问题我将不得不忍受?以下是一些代码:

I'm looking to take in an image of 162x193 pixels and basically scale it down by 0.125 i.e 162/8 = 20.25 and 193/8 = 24.125. Thus I would like a picture of size 20x24 The only problem I'm currently having is that when I use the imresize function it rounds up the images pixel values i.e I get an image of size 21x25 instead of 20x24. Any way of getting 20x24 or is this problem something I'm going to have to live with? Here is some code:

    //Read in original Image
    imageBig = imread(strcat('train/',files(i).name));  
    //Resize the image
    image = imresize(imageBig,0.125);
    disp(size(image));


推荐答案

看来正在提供比例参数, imresize ceils 按结果显示尺寸。所以,我猜一个明显的选择是手动为它提供舍入的值作为维度。

It appears that with the scale argument being provided, imresize ceils up the dimensions as your results show. So, I guess an obvious choice is to manually provide it the rounded values as dimensions.

代码

%%// Scaling ratio
scale1 = 0.125;

%%// Get scaled up/down version
[M,N,~] = size(imageBig);
image = imresize(imageBig,[round(scale1*M) round(scale1*N)]);

这篇关于Matlab imresize功能舍入像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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