Skip to content
Snippets Groups Projects
Commit cdd4eeac authored by Laura Nervo's avatar Laura Nervo
Browse files

gtFindDirectBeamBB : using bbdir as variable, instead of bb not to get confused


Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 33ac2499
No related branches found
No related tags found
No related merge requests found
function bb = gtFindDirectBeamBB(acq) function bbdir = gtFindDirectBeamBB(acq)
% GTFINDDIRECTBEAMBB Gives approximate bounding box of direct beam % GTFINDDIRECTBEAMBB Gives approximate bounding box of direct beam
% bb = gtFindDirectBeamBB(acq) % bbdir = gtFindDirectBeamBB(acq)
% ---------------------------- % -------------------------------
% INPUT: % INPUT:
% acq = acquisition structure in parameters.mat % acq = acquisition structure in parameters.mat
% %
% OUTPUT: % OUTPUT:
% bb = bounding box <double 1x4> % bbdir = direct beam bounding box <double 1x4>
% %
% Version 004 26/04/2012 by LNervo % Version 004 26/04/2012 by LNervo
% Replace sprtinf by fullfile % Replace sprtinf by fullfile
...@@ -99,7 +99,7 @@ else % no images found! ...@@ -99,7 +99,7 @@ else % no images found!
disp('using a default guess'); disp('using a default guess');
disp('%%%%%%% missing images %%%%%%%%'); disp('%%%%%%% missing images %%%%%%%%');
disp(' '); disp(' ');
bb = [512 512 1024 1024]; bbdir = [512 512 1024 1024];
return return
end end
...@@ -116,36 +116,36 @@ marker = zeros(acq.ydet, acq.xdet); ...@@ -116,36 +116,36 @@ marker = zeros(acq.ydet, acq.xdet);
marker(round(acq.ydet/2), round(acq.xdet/2)) = 1; marker(round(acq.ydet/2), round(acq.xdet/2)) = 1;
cen = imreconstruct(marker, cen); cen = imreconstruct(marker, cen);
tmp = regionprops(cen, 'BoundingBox'); tmp = regionprops(cen, 'BoundingBox');
bb = tmp.BoundingBox; bbdir = tmp.BoundingBox;
% Tighten bb until it's fully filled % Tighten bb until it's fully filled
bb = [ceil(bb(1:2)), bb(3:4)-1]; bbdir = [ceil(bbdir(1:2)), bbdir(3:4)-1];
goon = true; goon = true;
while goon while goon
cenbb = gtCrop(cen, bb); cenbb = gtCrop(cen, bbdir);
goon = false; goon = false;
if any(~cenbb(:, 1)) % tighten bb on the left if any(~cenbb(:, 1)) % tighten bb on the left
bb(1) = bb(1)+1; bbdir(1) = bbdir(1)+1;
bb(3) = bb(3)-1; bbdir(3) = bbdir(3)-1;
goon = true; goon = true;
end end
if any(~cenbb(:, end)) % tighten bb on the right if any(~cenbb(:, end)) % tighten bb on the right
bb(3) = bb(3)-1; bbdir(3) = bbdir(3)-1;
goon = true; goon = true;
end end
cenbb = gtCrop(cen, bb); cenbb = gtCrop(cen, bbdir);
if any(~cenbb(1, :)) % tighten bb at the top if any(~cenbb(1, :)) % tighten bb at the top
bb(2) = bb(2)+1; bbdir(2) = bbdir(2)+1;
bb(4) = bb(4)-1; bbdir(4) = bbdir(4)-1;
goon = true; goon = true;
end end
if any(~cenbb(end, :)) % tighten bb at the bottom if any(~cenbb(end, :)) % tighten bb at the bottom
bb(4) = bb(4)-1; bbdir(4) = bbdir(4)-1;
goon = true; goon = true;
end end
end end
...@@ -155,54 +155,54 @@ goon = true; ...@@ -155,54 +155,54 @@ goon = true;
while goon while goon
goon = false; goon = false;
tmpbb = bb+[-1 0 1 0]; % loose bb on the left tmpbb = bbdir+[-1 0 1 0]; % loose bb on the left
tmpim = gtCrop(cen, tmpbb); tmpim = gtCrop(cen, tmpbb);
if all(tmpim(:)) if all(tmpim(:))
bb = tmpbb; bbdir = tmpbb;
goon = true; goon = true;
end end
tmpbb = bb+[0 0 1 0]; % loose bb on the right tmpbb = bbdir+[0 0 1 0]; % loose bb on the right
tmpim = gtCrop(cen, tmpbb); tmpim = gtCrop(cen, tmpbb);
if all(tmpim(:)) if all(tmpim(:))
bb = tmpbb; bbdir = tmpbb;
goon = true; goon = true;
end end
tmpbb = bb+[0 -1 0 1]; % loose bb at the top tmpbb = bbdir+[0 -1 0 1]; % loose bb at the top
tmpim = gtCrop(cen, tmpbb); tmpim = gtCrop(cen, tmpbb);
if all(tmpim(:)) if all(tmpim(:))
bb = tmpbb; bbdir = tmpbb;
goon = true; goon = true;
end end
tmpbb = bb+[0 0 0 1]; % loose bb at the bottom tmpbb = bbdir+[0 0 0 1]; % loose bb at the bottom
tmpim = gtCrop(cen, tmpbb); tmpim = gtCrop(cen, tmpbb);
if all(tmpim(:)) if all(tmpim(:))
bb = tmpbb; bbdir = tmpbb;
goon = true; goon = true;
end end
end end
% make sure the bbox width and height are even numbers (needed for correlation) % make sure the bbox width and height are even numbers (needed for correlation)
bb(3:4) = ceil(bb(3:4)/2)*2; bbdir(3:4) = ceil(bbdir(3:4)/2)*2;
% plot bbox found, its center-line and center-line of image % plot bbox found, its center-line and center-line of image
bbcenter_abs = ((2*bb(1))+bb(3)-1)/2; bbcenter_abs = ((2*bbdir(1))+bbdir(3)-1)/2;
hfig = figure('name', 'Direct beam bounding box'); hfig = figure('name', 'Direct beam bounding box');
iniZoomFactor = min(size(ref)./bb(3:4)) * 0.7; iniZoomFactor = min(size(ref)./bbdir(3:4)) * 0.7;
colormap gray; colormap gray;
imagesc(ref); imagesc(ref);
zoom(iniZoomFactor); zoom(iniZoomFactor);
drawnow; drawnow;
hold on; hold on;
plot([bb(1), bb(1)+bb(3)-1, bb(1)+bb(3)-1, bb(1), bb(1)], [bb(2), bb(2), bb(2)+bb(4)-1, bb(2)+bb(4)-1, bb(2)], 'r-'); plot([bbdir(1), bbdir(1)+bbdir(3)-1, bbdir(1)+bbdir(3)-1, bbdir(1), bbdir(1)], [bbdir(2), bbdir(2), bbdir(2)+bbdir(4)-1, bbdir(2)+bbdir(4)-1, bbdir(2)], 'r-');
plot([acq.xdet/2+0.5 acq.xdet/2+0.5], [1 acq.ydet], 'b-.'); % centre of the ccd plot([acq.xdet/2+0.5 acq.xdet/2+0.5], [1 acq.ydet], 'b-.'); % centre of the ccd
plot([bbcenter_abs bbcenter_abs], [bb(2) bb(2)+bb(4)-1], 'c-.'); % centre of the direct beam plot([bbcenter_abs bbcenter_abs], [bbdir(2) bbdir(2)+bbdir(4)-1], 'c-.'); % centre of the direct beam
% interactive check % interactive check
questionMsg = 'Are you satisfied with this bounding box for the direct beam? [y/n]'; questionMsg = 'Are you satisfied with this bounding box for the direct beam? [y/n]';
...@@ -211,21 +211,21 @@ while (strcmpi(inputwdefault(questionMsg, 'n'), 'n')) ...@@ -211,21 +211,21 @@ while (strcmpi(inputwdefault(questionMsg, 'n'), 'n'))
disp('-> please click top-left and bottom-right corners'); disp('-> please click top-left and bottom-right corners');
figure(hfig), clf, imagesc(ref), zoom(iniZoomFactor), drawnow, hold on; figure(hfig), clf, imagesc(ref), zoom(iniZoomFactor), drawnow, hold on;
bb = ginput(2); bbdir = ginput(2);
bb = round([bb(1, 1) bb(1, 2) bb(2, 1)-bb(1, 1)+1 bb(2, 2)-bb(1, 2)+1]); bbdir = round([bbdir(1, 1) bbdir(1, 2) bbdir(2, 1)-bbdir(1, 1)+1 bbdir(2, 2)-bbdir(1, 2)+1]);
% Make sure the bbox width and height are even numbers (needed for correlation) % Make sure the bbox width and height are even numbers (needed for correlation)
bb(3:4) = ceil(bb(3:4)/2)*2; bbdir(3:4) = ceil(bbdir(3:4)/2)*2;
% Reset figure % Reset figure
zoomFactor = min(size(ref)./bb(3:4)) * 0.95; zoomFactor = min(size(ref)./bbdir(3:4)) * 0.95;
figure(hfig), clf, imagesc(ref), zoom(zoomFactor), drawnow, hold on; figure(hfig), clf, imagesc(ref), zoom(zoomFactor), drawnow, hold on;
% Plot the new bounding box % Plot the new bounding box
plot([bb(1), bb(1)+bb(3)-1, bb(1)+bb(3)-1, bb(1), bb(1)], [bb(2), bb(2), bb(2)+bb(4)-1, bb(2)+bb(4)-1, bb(2)], 'r-'); plot([bbdir(1), bbdir(1)+bbdir(3)-1, bbdir(1)+bbdir(3)-1, bbdir(1), bbdir(1)], [bbdir(2), bbdir(2), bbdir(2)+bbdir(4)-1, bbdir(2)+bbdir(4)-1, bbdir(2)], 'r-');
bbcenter_abs = ((2*bb(1))+bb(3)-1)/2; bbcenter_abs = ((2*bbdir(1))+bbdir(3)-1)/2;
plot([acq.xdet/2+0.5 acq.xdet/2+0.5], [1 acq.ydet], 'b-.'); plot([acq.xdet/2+0.5 acq.xdet/2+0.5], [1 acq.ydet], 'b-.');
plot([bbcenter_abs bbcenter_abs], [bb(2) bb(2)+bb(4)-1], 'c-.'); % centre of the direct beam plot([bbcenter_abs bbcenter_abs], [bbdir(2) bbdir(2)+bbdir(4)-1], 'c-.'); % centre of the direct beam
end end
close(hfig); close(hfig);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment