主要内容

blockproc

图像的独特块处理

描述

例子

b= blockproc (一个,,,,[m n],,,,funprocesses the image一个通过应用功能fun到每个不同大小的块[m n]and concatenating the results into the output image,b

例子

b= blockproc (src_filename,,,,[m n],,,,funprocesses the image with file namesrc_filename,,,,reading and processing one block at a time. This syntax is useful for processing large images.

b= blockproc (适配器,,,,[m n],,,,fun处理由适配器, 一个ImageAdapter目的。如果您需要自定义API来读取和写入特定图像文件格式,请使用此语法。

例子

blockproc(___,,,,名称,价值使用名称值对参数来控制块行为的各个方面。

例子

全部收缩

Read image into the workspace.

i = imread('Pears.png');

创建块处理功能。

fun = @(block_struct)imresize(block_struct.data,0.15);

处理图像,逐个块。

i2 = blockproc(I,[100 100],fun);

显示原始图像和处理的图像。

数字;imshow(i);

图包含一个轴对象。轴对象包含类型图像的对象。

数字;imshow(i2);

图包含一个轴对象。轴对象包含类型图像的对象。

创建块处理功能。

fun = @(block_struct)。。。std2(block_struct.data) *一个(size(block_struct.data));

执行块处理操作,并通过文件名指定输入图像。

i2 = blockproc('Moon.tif',[32 32],有趣);

显示原始图像和处理的版本。

数字;imshow('Moon.tif');

图包含一个轴对象。轴对象包含类型图像的对象。

数字;imshow(i2,[]);

图包含一个轴对象。轴对象包含类型图像的对象。

Read image into the workspace.

i = imread('peppers.png');

创建块处理功能。

fun = @(block_struct)block_struct.data(::,:,[2 1 3]);

执行块处理操作。

blockproc(I,[200 200],fun,'Destination',,,,'grb_peppers.tif');

显示原始图像和处理的图像。

数字;imshow('peppers.png');

图包含一个轴对象。轴对象包含类型图像的对象。

数字;imshow('grb_peppers.tif');

图包含一个轴对象。轴对象包含类型图像的对象。

笔记: To run this example, you must replace'lighimage.tif'用文件的名称。

创建块处理功能。

fun = @(block_struct)block_struct.data;

将TIFF图像转换为新的JPEG2000图像。代替'lighimage.tif'with the name of an actual image file.

blockproc('lighimage.tif',,,,[1024 1024],fun,'Destination',,,,'new.jp2');

输入参数

全部收缩

要处理的图像,指定为数字阵列。

源文件名,,,,specified as a character vector or string scalar. Files must have one of these file types and must be named with one of the listed file extensions.

  • tiff( *.tif, *.tiff)

  • jpeg2000( *.jp2, *.jpf, *.jpx, *.j2c, *.j2k)

Data Types:char|string

图像适配器,指定为ImageAdapter目的。一个ImageAdapteris a user-defined class that providesblockproc具有通用的API,用于读取和写入特定的图像文件格式。有关更多信息,请参阅Perform Block Processing on Image Files in Unsupported Formats

块大小,指定为2元素向量。m是行的数量nis the number of columns in the block.

功能句柄,,,,specified as a handle. The function must accept ablock_struct作为输入并返回数组,向量或标量。如果funreturns empty, thenblockprocdoes not generate any output and returns empty after processing all blocks.

For more information about function handles, seeCreate Function Handle

名称值参数

指定可选的逗号分隔对名称,价值参数。Name是参数名称和Valueis the corresponding value.Name必须出现在引号中。您可以按任何顺序指定几个名称和值对参数NAME1,Value1,...,Namen,Valuen

例子:“边界”,[8 4]

Destination for the output, specified as the comma-separated pair consisting of'Destination'以及以下内容之一。When you specify the'Destination'争论,blockproc不会将处理的图像作为输出参数返回,而是将输出写入目标文件。

  • 带有目标文件名的字符向量或字符串标量。文件必须具有以下文件类型之一,并且必须用列出的文件扩展名之一命名。

    • tiff( *.tif, *.tiff)

    • jpeg2000( *.jp2, *.j2c, *.j2k)

    如果a file with this name exists, then it is overwritten.

  • 一个ImageAdapter对象,它提供了用于读取和写入特定图像文件格式的常见API。有关更多信息,请参阅Perform Block Processing on Image Files in Unsupported Formats

'Destination'当您期望输出太大而无法适应内存时,参数很有用。它为任意大图像的文件对文件图像处理提供了一个工作流程。

笔记

指定输出参数不能请求输出参数'Destination'争论。

要添加到每个块的边框像素的数量,指定为逗号分隔对“边界”and a 2-element vector of positive integers, of the form[v h]。这function addsv每个块上方和下方的行H每个块的左右列。每个结果块的大小是:

[M+2*V,N+2*H]

默认情况下,aut的函数omatically removes the border from the result offun。看到TrimBorder争论更多信息。

函数板块带有边框延伸的边缘超出图像边缘的零边缘。

垫部分块to make them full-sized, specified as the comma-separated pair consisting of“ padpartialblocks”and错误的ortrue。当图像大小不完全由块大小排除时,就会出现部分块。如果存在,部分块位于图像的右侧和底部边缘。

设置为true,,,,blockproc垫子部分块使它们全尺寸m-经过-nblocks. The default is错误的,这意味着该函数不会填充部分块,而是对其进行处理。blockproc必要时使用零来填充部分块。

Method used to pad the image boundary, specified as the comma-separated pair consisting of'padMethod'以及以下内容之一。

Value 描述
'replicate' 重复边框元素。
“对称” 带有镜子反射的垫图像。
数字标量 带标量值的垫图像。默认情况下,图像边界带有值0

Data Types:char|string

从用户函数的输出中删除边框像素,指定为逗号分隔对,由'TrimBorder'andtrueor错误的。设置为true, 这blockproc功能从用户函数的输出中删除边框像素,fun。函数删除vrows from the top and bottom of the output offun, 一个dHcolumns from the left and right edges. TheborderSizeargument definesvandH

使用并行处理,指定为逗号分隔对“ useparalallel'and错误的ortrue。如果已安装并行计算工具箱™,则设置为true,Matlab®automatically opens a parallel pool of workers on your local machine.blockprocruns the computation across the available workers. For more information, see大型图像文件上的平行块处理

Display wait bar, specified as the comma-separated pair consisting of“ DisplayWaitbar”andtrueor错误的。设置为true,,,,blockproc显示一个等待栏,以指示长期运行的进度。阻止blockproc通过显示等待栏,设置DisplayWaitbarto错误的

Output Arguments

全部收缩

Processed image, returned as a numeric array.

更多关于

全部收缩

block Struct

一个块结构是一种MATLAB结构,其中包含块数据和有关块的其他信息。字段中的字段块结构是:

场地 描述
border 形式的2元素向量[v h]。这borderfield specifies the size of the vertical and horizontal padding around the block of data. See theborderSize争论更多信息。
blockSize 形式的2元素向量[行科尔斯]。这blockSize字段指定块数据的大小。如果指定边框,则大小不包括边框像素。
数据 m-经过-norm-经过-n-经过-p块数据数组。
图片尺寸 形式的2元素向量[行科尔斯]。这图片尺寸字段指定输入图像的全尺寸。
location 形式的2元素向量[row col]。这locationfield specifies the position of the first pixel (minimum-row, minimum-column) of the block data in the input image. If a border has been specified, the location refers to the first pixel of the discrete block data, not the added border pixels.

提示

  • Choosing an appropriate block size can significantly improve performance. For more information, seeblock Size and Performance

  • 如果输出图像b太大而无法适应内存,然后省略输出参数,而是使用Destination名称值对参数将输出写入文件。

  • blockproccan read BigTIFF images but has limited support for writing BigTIFF images to file. If you write an image to file, thenblockproc根据文件的大小自动选择文件类型。如果图像小于或等于4.0 GB,则blockproc将图像保存为标准TIFF图像。如果文件的大小大于4.0 GB,则blockprocsaves the image as a BigTIFF image.

    blockprocdoes not provide an argument that enables you to specify the file type as BigTIFF when the file size is less than or equal to 4.0 Gb. If you want to write a small image as a BigTIFF file, then specify a custom image adapter using the适配器争论。有关更多信息,请参阅TIFF,BIGTIFF和BLOCKPROC

  • 要确定书面TIFF文件是标准TIFF还是BIGTIFF,请查询图像格式签名imfinfo功能:

    tiffinfo = imfinfo(Destination); tiffformat = tiffinfo.FormatSignature

    如果最后一个非零值为tiffformat为42,然后文件为标准TIFF格式。如果最后一个非零值为43,则文件为Bigtiff格式。

Extended Capabilities

在R2009b中引入