[英]How to used linspace matlab function to get the and the y of all pixels in image?
[英]Get center pixels of image in matlab
我想提取图像大小(p*hight,p*width,3)
的矩形区域。 p是[0,1]之间的双精度值。
以下代码有效,但是我想知道是否有更好的方法来实现这一目标?
img = imread(ImageName);
% size parameter
p = 0.5;
% store image size
hight = size(img,1);
width = size(img,2);
% calculate the center of the image both in width and hight
% used as reference
centerHight = floor(hight/2);
centerWidth = floor(width/2);
% use half of the actual size of the rectangular region
halfHight = floor(p*hight/2);
halfWidth = floor(p*width/2);
% start index for hight and width
startHight = 1 + centerHight - halfHight;
startWidth = 1 + centerWidth - halfWidth;
% end index for hight and width
endHight = centerHight + halfHight;
endWidth = centerWidth + halfWidth;
% extract center pixels
CenterPixels = img(startHight:endHight,startWidth:endWidth,:);
是否有任何matlab命令可获得相同的结果? 也许只指定矩形的大小和图像中心?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.