MATLAB_分割切り出し - tajima1121/practice_repository GitHub Wiki

ASAPでCAMELYONのtiff画像を表示
0からASAP上でCAMELYONのtiff画像を表示するまでの流れ
MATLABを使ってTIFFから第1レイヤーの画像を取り出す
MATLABでのTIFFから第1レイヤーの画像の読み込み

T=imread('/Users/kindo/Documents/MATLAB/tumor_009-029.tif');

田島の場合、tumor_001
SIZE_MAX_X 96000; // 96000px
SIZE_MAX_Y 216000; // 216000px

4分割するので、yを4分割する。
y1_end_point = 54000;
y2_end_point = 108000;
y3_end_point = 162000;
y4_end_point = 216000;
y1_start_point = 1;
y2_start_point = y1_end_point + 1;
y3_start_point = y2_end_point + 1;
y4_start_point = y3_end_point + 1;

T1 = imread('/Users/tajima/Documents/MATLAB/tumor_001.tif','PixelRegion',{[y1_start_point,y1_end_point],[1,96000]});
T2 = imread('/Users/tajima/Documents/MATLAB/tumor_001.tif','PixelRegion',{[y2_start_point,y2_end_point],[1,96000]});
T2 = imread('/Users/tajima/Documents/MATLAB/tumor_001.tif','PixelRegion',{[y2_start_point,y2_end_point],[1,96000]});
T2 = imread('/Users/tajima/Documents/MATLAB/tumor_001.tif','PixelRegion',{[y2_start_point,y2_end_point],[1,96000]});

T=imread('/Users/tajima/Documents/MATLAB/tumor_001.tif');
y x
T1 = imread('/Users/tajima/Documents/MATLAB/tumor_001.tif','PixelRegion',{[1,54000],[1,96000]});

MATLABで、画像を分割して、PNGフォーマットで書き出す(分割しないと書き出せない
以下の分割&書き出し関数を作成して、MATLABのワークフォルダに cropAndSaveBlock.m という名前でセーブする
function cropAndSaveBlock(bs)
save_loc ='./output';
fileName = [save_loc, '/img', int2str(bs.location(1)), '_', int2str(bs.location(2)), '.png'];
imwrite(bs.data, fileName)
end

blockSize=[2160 3840]; //4Kのサイズを指定する
blockproc(T,blockSize,@cropAndSaveBlock); //Tとして読み出した画像
をblockSizeに分割して保存する

実際のプログラム↓↓

blockSize=[2160 3840]; //4Kのサイズを指定する

y1_end_point = 54000;
y2_end_point = 108000;
y3_end_point = 162000;
y4_end_point = 216000;
y1_start_point = 1;
y2_start_point = y1_end_point + 1;
y3_start_point = y2_end_point + 1;
y4_start_point = y3_end_point + 1;

T1 = imread('D:/00_kindoLab/source/tumor/tumor001/tif/tumor_001.tif','PixelRegion',{[y1_start_point,y1_end_point],[1,96000]});
blockproc(T1,blockSize,@cropAndSaveBlock_T1);
T2 = imread('D:/00_kindoLab/source/tumor/tumor001/tif/tumor_001.tif','PixelRegion',{[y2_start_point,y2_end_point],[1,96000]});
blockproc(T2,blockSize,@cropAndSaveBlock_T2);
T3 = imread('D:/00_kindoLab/source/tumor/tumor001/tif/tumor_001.tif','PixelRegion',{[y3_start_point,y3_end_point],[1,96000]});
blockproc(T3,blockSize,@cropAndSaveBlock_T3);
T4 = imread('D:/00_kindoLab/source/tumor/tumor001/tif/tumor_001.tif','PixelRegion',{[y4_start_point,y4_end_point],[1,96000]});
blockproc(T4,blockSize,@cropAndSaveBlock_T4);

function cropAndSaveBlock_tumor_001_T1(bs)
size_plus_y = 0; size_y = int2str(bs.location(1)) + size_plus_y; save_loc ='D:/00_kindoLab/source/tumor/tumor001/4Ksize/';
fileName = [save_loc, '/tumor_001_', size_y, '_', int2str(bs.location(2)), '.png'];
imwrite(bs.data, fileName);
end