matlab tile,Tile Simulink Diagrams

Create Report with Image Tiles

Open a model with a large diagram.

model = 'slreportgen_demo_big_diagram';

open_system(model);

Create large image file to split into tiles.

imgFile = [model '.png'];

print('-dpng', ['-s' model], imgFile);

Create and open a report.

% To create a Word report, change the output type from "pdf" to "docx".

% To create an HTML report, change "pdf" to "html" or "html-file for

% a multifile or single-file report, respectively.

rpt = slreportgen.report.Report('myreport2', 'pdf');

open(rpt);

Get the page layout information.

pageLayout = rpt.Document.CurrentPageLayout;

pageSize = pageLayout.PageSize;

pageMargins = pageLayout.PageMargins;

Set the page header and footer to 0 inches to maximize space.

pageMargins.Header = '0in';

pageMargins.Footer = '0in';

Determine the image tile size that fits onto the page. The optimal tile size is the page size minus the page margins, gutters, headers and footers. Also, adjust the tile height to allow 0.5 inches for the caption. Note that for PDF documents, MATLAB Report Generator defines one inch as equal to 96 pixels.

dpi = 96;

units = mlreportgen.utils.units;

tileHeight = units.toPixels(pageSize.Height, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Top, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Bottom, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Header, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Footer, 'Resolution', dpi) ...

- units.toPixels('0.5in', 'Resolution', dpi);

tileWidth = units.toPixels(pageSize.Width, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Left, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Right, 'Resolution', dpi) ...

- units.toPixels(pageMargins.Gutter, 'Resolution', dpi);

tileSize = [tileWidth tileHeight];

Call the sliceImage local function (see below) to slice the large image file into image tiles.

tiles = sliceImage(imgFile, [tileWidth tileHeight]);

Add the tile images to the report. Also, also add a caption to indicate where the tile image belongs in relation to the overall image.

for i = 1:numel(tiles)

tile = tiles{i};

formalImage = mlreportgen.report.FormalImage(tile.File);

formalImage.ScaleToFit = false;

formalImage.Caption = sprintf('row: %d, col: %d', tile.Row, tile.Col);

add(rpt, formalImage);

end

Generate and display the report.

close(rpt);

rptview(rpt);

Define sliceImage Local Function

To slice an image file into tiles, read in the image file and copy tile-size parts into multiple image files.

function tiles = sliceImage(imgFile, tileSize)

% Read in the image file and determine the number of row and column

% tiles. Note that the image data is row-major, where the rows are

% specified first and the columns are second.

img = imread(imgFile);

imgSize = size(img);

imgRows = imgSize(1); % image height

imgCols = imgSize(2); % image width

tileNumRows = tileSize(2); % tile height

tileNumCols = tileSize(1); % tile width

numCols = ceil(imgCols / tileNumCols);

numRows = ceil(imgRows / tileNumRows);

% Preallocate the tile data structures.

tiles = cell(1, numCols*numRows);

% Determine the base filename to create the tile image filenames.

[fPath, fName, fExt] = fileparts(imgFile);

tileName = fullfile(fPath, fName);

% Iterate through all rows and columns.

count = 0;

for rowIdx = 1:numRows

for colIdx = 1:numCols

% Determine the starting and ending image data indices to copy

% into the tile image. At the edges, the ending indices are

% the number of rows and number of columns.

rowStart = (rowIdx - 1) * tileNumRows + 1;

rowEnd = rowStart + tileNumRows - 1;

colStart = (colIdx - 1) * tileNumCols + 1;

colEnd = colStart + tileNumCols - 1;

if (rowEnd >= imgRows)

rowEnd = imgRows;

end

nTileRows = rowEnd - rowStart + 1;

if (colEnd >= imgCols)

colEnd = imgCols;

end

nTileCols = colEnd - colStart + 1;

% Copy the tile image data onto a white image tile.

tileImg = uint8(255 * ones(tileNumRows, tileNumCols, 3));

tileImg(1:nTileRows, 1:nTileCols, :) = img(rowStart:rowEnd,...

colStart:colEnd, :);

% Write out the image tile.

outFile = sprintf('%s_%d_%d.%s', tileName, rowIdx, colIdx, fExt);

imwrite(tileImg, outFile);

% Create the tile data structure to describe the tile.

count = count + 1;

tiles{count} = struct( ...

'File', outFile, ...

'Row', rowIdx, ...

'Col', colIdx);

end

end

end

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值