setBlock
(削除予定) bigimage オブジェクトの特定のブロックへのデータの配置
bigimage オブジェクトの関数 setBlock は将来のリリースで削除される予定です。代わりに、blockedImage オブジェクトに関連付けられた関数 setBlock を使用してください。詳細については、バージョン履歴を参照してください。
説明
setBlock( は、指定された解像度レベルで座標 bigimg,level,locationWorld,data)locationWorld を含む大きなイメージ bigimg のブロックにピクセル データを設定します。
例
CAMELYON16 データセットのイメージ "tumor_091.tif" の変更したバージョンを使用して bigimage を作成します。元のイメージは、腫瘍組織が含まれるリンパ節の学習イメージです。元のイメージには 8 つの解像度レベルがあり、最も細かいレベルの解像度は 53760 x 61440 です。変更したイメージには、3 つの粗い解像度レベルのみが含まれています。変更したイメージの空間参照は、縦横比が一定に維持され、各レベルで特徴がレジストレーションされるように調整されています。
bim = bigimage('tumor_091R.tif');
bigimage を表示し、表示されたイメージの上に円 ROI を作成します。
h = bigimageshow(bim); hROI = drawcircle(gca,'Radius',470,'Position',[1477 2284]);

書き換え可能な bigimage を作成するレベルを選択します。レベル 3 は最も粗い解像度レベルです。
maskLevel = 3;
指定されたレベルから空間参照とピクセル範囲を取得します。
ref = bim.SpatialReferencing(maskLevel); pixelExtent = [ref.PixelExtentInWorldX,ref.PixelExtentInWorldY];
イメージ データではなく空間参照を指定して、書き換え可能な bigimage を作成します。大きなイメージには 1 つのチャネルがあり、データ型は logical です。
bmask = bigimage(ref,1,'logical');
書き換え可能な大きなイメージ内のすべてのブロックでループ処理を行い、マスク イメージを作成します。ブロックごとに、ROI 内のピクセルではピクセル値を 1 (true) として設定し、ROI 外のピクセルでは 0 (false) として設定します。
for cStart = 1:bmask.BlockSize(2):ref.ImageSize(2) for rStart = 1:bmask.BlockSize(1):ref.ImageSize(1) % Get the center of top left pixel of this block in world units. xyStart = [cStart,rStart].*pixelExtent; % Get the block size. The |'BlockSize'| property represents the % size as a 2-element vector of the form [row,column]. Switch the % order of the elements so that the block size is represented as % [x,y]. bsize = bmask.BlockSize; numRows = bsize(1); numCols = bsize(2); % Determine which pixels have coordinates inside the ROI. roiPositions = hROI.Vertices; % Transform |roiPositions| from world coordinates to the intrinsic % image indices at the given resolution level. roiPositions = (roiPositions - xyStart) ./ pixelExtent + 1; blockMask = poly2mask(roiPositions(:,1),roiPositions(:,2), ... numRows, numCols); % Set the pixel values of the block. setBlock(bmask,1,xyStart,blockMask); end end
マスクを表示します。
figure bigimageshow(bmask)

入力引数
ヒント
イメージ データを初期化しない構文を使用して、書き換え可能な
bigimageを作成します。イメージ データのファイル名、ディレクトリ名、または変数名を指定して、または関数applyを使用してbigimageを作成する場合、bigimageは書き換え可能にならず、関数setBlockを使用できません。dataのサイズがブロック サイズbigimg.BlockSizeより小さい場合、setBlockは既定値bigimg.UnloadedValueを使用してデータをパディングします。setBlockは部分エッジ ブロックのデータをトリミングします。
バージョン履歴
R2019b で導入setBlock 関数は、将来のリリースで削除されるという警告を発行します。
bigimage オブジェクトとこの関数は将来のリリースで削除される予定です。代わりに、blockedImage オブジェクトの関数 setBlock を使用してください。
コードを更新するには、まず、イメージ データを書き込むための書き込み可能な blockedImage オブジェクトを作成します。次に、以下の手順に従います。
2 つの要素の順序を入れ替えて、(x, y) ワールド座標を (行, 列) ワールド座標に変換します。
関数
world2subを使用して、ワールド座標をピクセルの添字に変換します。レベル 1 以外の解像度レベルでブロックを設定するには、名前と値の引数Levelを使用してそのレベルを指定します。関数
sub2blocksubを使用して、ピクセルの添字をブロックの添字に変換します。レベル 1 以外の解像度レベルでブロックを設定するには、名前と値の引数Levelを使用してそのレベルを指定します。blockedImageの関数setBlockは、ブロック サイズと等しいデータ サイズを必要とします。ブロック サイズより小さいサイズのblockedImageデータを設定するには、データをパディングします。ブロック化されたイメージ、ブロックの添字、および書き込むデータを関数
setBlockに渡します。レベル 1 以外の解像度レベルでブロックを設定するには、名前と値の引数Levelを使用してそのレベルを指定します。blockedImageオブジェクトにデータを書き込んだ後、オブジェクトのモードを読み取り専用に変更してから、イメージ データを取得しなければなりません。たとえば、ドット表記を使用してModeプロパティを"r"に設定し、blockedImageオブジェクトblockedMaskのモードを変更します。blockedMask.Mode = "r";一方、書き込んだデータは、オブジェクトのプロパティを変更することなく、
bigimageオブジェクトから読み取ることができます。
| 非推奨の使用方法 | 推奨される代替案 |
|---|---|
この例では、関数 % Create a writeable bigimage object filename = "tumor_091R.tif"; bim = bigimage(filename); ref = bim.SpatialReferencing(1); blockSize = bim.BlockSize(1,1:2); bigMask = bigimage(ref,1,"logical"); % Identify a coordinate coordWorld = [1000 2500]; % Specify the data to write, then write the data blockSize = bim.BlockSize(1,1:2); data = logical(checkerboard(blockSize(1)/16,8)); setBlock(bigMask,1,coordWorld,data); | 以下は、 % Create a writeable blockedImage object filename = "tumor_091R.tif"; blockedIm = blockedImage(filename); imgSize = blockedIm.Size(1,1:2); blockSize = blockedIm.BlockSize(1,1:2); initVal = logical(0); blockedMask = blockedImage([],imgSize,blockSize,initVal,Mode="w"); % Identify the block containing a coordinate coordWorld = [1000 2500]; coordRC = flip(coordWorld); subPixel = world2sub(blockedMask,coordRC); subBlock = sub2blocksub(blockedMask,subPixel); % Specify the data to write, then write the data to the block data = logical(checkerboard(blockSize(1)/16,8)); setBlock(blockedMask,subBlock,data); |
この例では、関数 % Create a writeable bigimage object % (same as above) % Identify a coordinate % (same as above) % Specify the data to write, then write the data data = logical(checkerboard(10,8)); setBlock(bmask,1,coordWorld,data); | 以下は、 % Create a writeable blockedImage object % (same as above) % Identify a coordinate % (same as above) % Specify the data to write, then write the data to the block data = logical(checkerboard(10,8)); data = padarray(data,blockSize-size(data),initVal,"post"); setBlock(blockedMask,subBlock,data); |
bigimage オブジェクトの関数 setBlock は推奨されません。代わりに、blockedImage オブジェクトの関数 setBlock を使用してください。blockedImage オブジェクトには、N 次元の処理に拡張できる、インターフェイスがシンプルである、非標準イメージ形式の読み書きをカスタムでサポートしている、といったいくつかの利点があります。
参考
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)