matlab 中 Transform,变换数据存储 - MATLAB transform - MathWorks 中国

为图像集合创建一个数据存储,并对数据存储中的所有图像应用相同的变换。例如,将集合中的所有图像调整到指定的目标大小。

创建一个包含两个图像的 ImageDatastore。

imds = imageDatastore({'street1.jpg','peppers.png'})

imds =

ImageDatastore with properties:

Files: {

' .../devel/bat/Bdoc20b/build/matlab/toolbox/matlab/demos/street1.jpg';

' .../devel/bat/Bdoc20b/build/matlab/toolbox/matlab/imagesci/peppers.png'

}

Folders: {

'/mathworks/devel/bat/Bdoc20b/build/matlab/toolbox/matlab/demos';

'/mathworks/devel/bat/Bdoc20b/build/matlab/toolbox/matlab/imagesci'

}

AlternateFileSystemRoots: {}

ReadSize: 1

Labels: {}

SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"]

DefaultOutputFormat: "png"

ReadFcn: @readDatastoreImage

读取所有图像。请注意,该数据存储包含不同大小的图像。

img1 = read(imds); % reads the first image

img2 = read(imds); % reads the next image

whos img1 img2

Name Size Bytes Class Attributes

img1 480x640x3 921600 uint8

img2 384x512x3 589824 uint8

将数据存储中的所有图像变换为指定的目标大小。

targetSize = [224,224];

imdsReSz = transform(imds,@(x) imresize(x,targetSize));

读取图像并显示其大小。

imgReSz1 = read(imdsReSz);

imgReSz2 = read(imdsReSz);

whos imgReSz1 imgReSz2

Name Size Bytes Class Attributes

imgReSz1 224x224x3 150528 uint8

imgReSz2 224x224x3 150528 uint8

显示调整大小后的图像。

subplot(121); imshow(imgReSz1); axis on; title('Resized Street1.jpg');

subplot(122); imshow(imgReSz2); axis on; title('Resized peppers.png');

9486c0eac38eb4f3a0921c093819156e.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值