1- function [regData ,ihcrs ,ifpaths ,b ,h ,w ,scale ,ihcscale ] = checkVars(ihc ,ifdir )
1+ %% checkVars
2+ %% Created by: Joshua Doyle
3+ %% Edited by: Benjamin Green
4+ %% -----------------------------------------------------------
5+ %% Description
6+ % part of the registration protocol for slides from different microscopes
7+ % reads in the images to memory and gets image parameters
8+ % -- Possible Improvement in readYCBCr2RGB for parloop reading in subset of
9+ % main IHC image to improve read time -- use imread 'Region Property'
10+ %% -----------------------------------------------------------
11+ function [regData ,ihcrs ,ifpaths ,b ,h ,w ,scale ,ihcscale ] ...
12+ = checkVars(ihc ,ifdir )
13+ %
214% pixels/u - Vectra scale (mft provided)
15+ %
316scale = 1.9981018 ;
17+ %
418% Number of bands in IF images
19+ %
520ncomponents = 8 ;
21+ %
622% pixels/u - Hamamatsu scale (mft provided)
23+ %
724ihcscale = 2.173913 ;
8-
9- if ~exist(' regData' , ' var' )
10- % myDir = uigetdir('Load Componenet Tiff Directory'); %gets directory
11- ifpaths = dir(fullfile(ifdir ,' *component_data.tif' ));
12-
13- regData = struct(' filename' ,{{}},' micronLoc' ,{{}},' regLoc' ,{{}});
14- for i1 = 1 : length(ifpaths )
15- baseFileName = ifpaths(i1 ).name;
16- % B = strsplit(baseFileName,'_');
17- % if length(B) > 3
18- % if strcmp(B{4},'binary')
19- % imstr.binaryfile = baseFileName;
20- % end
21- % if strcmp(B{4},'composite')
22- % imstr.componentfile = baseFileName;
23- % end
24- % if strcmp(B{4},'phenotype')
25- % imstr.phenofile = baseFileName;
26- % end
27- %
28- % if strcmp(B{8},'component')
29- % imstr.compositefile = baseFileName;
30- regData.filename{i1 } = baseFileName ;
31- C = strsplit(baseFileName ,{' [' ,' ,' ,' ]' });
32- % TODO
33- % add if wholeslide || if TMA
34- regData.micronLoc{i1 } = [str2double(C{2 }) str2double(C{3 })];
35- % regData.micronLoc{i1} = [str2double(C{6}) str2double(C{7})];
36- % end
37- % end
38- end
39- b = cast(reshape(cell2mat(regData .micronLoc ),2 ,[]),' uint32' )' ;
25+ %
26+ % get if image names
27+ %
28+ ifpaths = dir(fullfile(ifdir , ' *component_data.tif' ));
29+ if isempty(ifpaths )
30+ msg = [' Error: could not find IF images in - ' ,ifpaths ];
31+ error(msg )
4032end
41-
42- % if ~exist('miData','var')
43- % load('miData');
44- % mirs = reshape(miData.mmi,[],1);
45- % midata2 = zeros(length(mirs),1);
46- % for i1 = 1:length(mirs)
47- % midata2(i1) = sum(mirs{i1}(:));
48- % end
49- % [ma,mind] = max(midata2);
50- % [I,J] = ind2sub([9,9],mind);
51- % end
52-
53- if ~exist(' ihcrs' ,' var' )
54-
55- % [ihcfile,ihcpath] = uigetfile('*/*.tif','Select a full slide image for registration');
56- % tobj = Tiff([ihcpath,ihcfile],'r');
57- tobj = Tiff(ihc ,' r' );
58- origh = getTag(tobj ,' ImageLength' );
59- origw = getTag(tobj ,' ImageWidth' );
60- ihcrs = imresize(readYCbCr2RGB(tobj ),[origh * scale / ihcscale ,origw * scale / ihcscale ]);
61-
62- % ihcrs = imresize(readYCbCr2RGB(tobj),[origh*scale/miData.param.scale{I,J}(2),origw*scale/miData.param.scale{I,J}(1)]);
63-
64- % tobjATP = Tiff('Z:\stitch\Hamamatsu Channel Images\M41-ATPase.tif','r');
65- % tobjHematox = Tiff('Z:\stitch\Hamamatsu Channel Images\M41-Hematoxyln.tif','r');
66- % origh = getTag(tobjATP,'ImageLength');
67- % origw = getTag(tobjATP,'ImageWidth');
68- % ihcrs(:,:,1) = imresize(read(tobjATP),[origh*scale/miData.param.scale{I,J}(2),origw*scale/miData.param.scale{I,J}(1)]);
69- % ihcrs(:,:,2) = imresize(read(tobjHematox),[origh*scale/miData.param.scale{I,J}(2),origw*scale/miData.param.scale{I,J}(1)]);
33+ %
34+ regData = struct(' filename' , {{}}, ' micronLoc' , {{}}, ' regLoc' , {{}});
35+ for i1 = 1 : length(ifpaths )
36+ baseFileName = ifpaths(i1 ).name;
37+ regData.filename{i1 } = baseFileName ;
38+ C = strsplit(baseFileName ,{' [' ,' ,' ,' ]' });
39+ regData.micronLoc{i1 } = [str2double(C{2 }) str2double(C{3 })];
7040end
71-
41+ %
42+ % variable for registered locations
43+ %
44+ b = cast(reshape(cell2mat(regData .micronLoc ),2 ,[]),' uint32' )' ;
45+ %
46+ % get IHC image and size params
47+ %
48+ if ~exist(ihc ,' file' )
49+ msg = [' Error: could not find IHC image - ' ,ihc ];
50+ error(msg )
51+ end
52+ %
53+ fprintf(1 , ' Reading %s\n ' , ihc );
54+ %
55+ tic
56+ imf = imfinfo(ihc );
57+ level = find(ismember({imf(: ).ImageDescription}, ' x20 z0' ));
58+ origh = imf(level ).Height;
59+ origw = imf(level ).Width;
60+ %
61+ img = imread(ihc ,level );
62+ ihcrs = imresize(img ,...
63+ [origh * scale / ihcscale ,origw * scale / ihcscale ]);
64+ clear img
65+ fprintf(' ' );
66+ toc
67+ %
68+ % get IF size params
69+ %
7270baseFileName = ifpaths(1 ).name;
7371fullFileName = fullfile(ifdir , baseFileName );
74- fprintf(1 , ' Now reading %s\n ' , fullFileName );
75- tobj = Tiff(fullFileName );
76- img = makeTifIm(tobj ,ncomponents );
77- [h ,w ,bands ] = size(img );
72+ img = imfinfo(fullFileName );
73+ h = img .Height ;
74+ w = img .Width ;
75+ regData.h = h ; % hpf height
76+ regData.w = w ; % hpf width
77+ %
78+ end
0 commit comments