From 8ee871bac389f0fa85a430fc98f3d2c7e83f4a67 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Thu, 19 Sep 2024 09:44:56 +0200 Subject: [PATCH] ref --- miss_hit.cfg | 6 ++-- .../plotting/createMontage.m | 28 ++++--------------- .../plotting/createOverlayMontage.m | 15 +++++----- src/plotting/initMontageFigure.m | 24 ++++++++++++++++ untitled.m | 13 +++++++-- 5 files changed, 50 insertions(+), 36 deletions(-) rename createMontage.m => src/plotting/createMontage.m (78%) rename createOverlayMontage.m => src/plotting/createOverlayMontage.m (90%) create mode 100644 src/plotting/initMontageFigure.m diff --git a/miss_hit.cfg b/miss_hit.cfg index d7a1a245..727d20b4 100644 --- a/miss_hit.cfg +++ b/miss_hit.cfg @@ -36,7 +36,7 @@ copyright_entity: "Wellcome Trust Centre for Neuroimaging" tab_width: 2 # metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html) -metric "cnest": limit 7 +metric "cnest": limit 4 metric "file_length": limit 1000 -metric "cyc": limit 22 -metric "parameters": limit 9 +metric "cyc": limit 20 +metric "parameters": limit 6 diff --git a/createMontage.m b/src/plotting/createMontage.m similarity index 78% rename from createMontage.m rename to src/plotting/createMontage.m index 6ca3c474..550bdef4 100644 --- a/createMontage.m +++ b/src/plotting/createMontage.m @@ -11,12 +11,14 @@ % 'cxs', [0 255]) % % - % Simple function to create a montage / mosaic of multiple slices from a single 3D + % Simple function to create a montage / + % mosaic of multiple slices from a single 3D % image matrix. % % INPUT: % img - 3D (x,y,z) image matrix - % columns - number of columns in montage (rows are calculated accordingly) + % columns - number of columns in montage + % (rows are calculated accordingly) % rotate - rotate images 90 deg clockwise? yes = 1; no = 0. % cmap - figure colormap % visibility - show figure? @@ -116,27 +118,7 @@ montage.whole_img = whole; end - % Get screen size for plotting - [1 1 w h] - scr_size = get(0, 'ScreenSize'); - dist = scr_size(4); - if scr_size(3) < dist - dist = scr_size(3); - end - - % Create figure - outerposition = [left bottom width height] - if strcmp(shape, 'max') - f = figure('visible', visibility, ... - 'units', 'normalized', ... - 'outerposition', [0 0 1 1]); - elseif strcmp(shape, 'square') - f = figure('visible', visibility, ... - 'units', 'pixels', ... - 'outerposition', [0 0 dist dist]); - else - f = figure('visible', visibility, ... - 'units', 'pixels', ... - 'outerposition', [0 0 dist dist]); - end + f = initMontageFigure(shape, visibility); ax = subplot(1, 1, 1); im = imagesc(ax, montage.whole_img); diff --git a/createOverlayMontage.m b/src/plotting/createOverlayMontage.m similarity index 90% rename from createOverlayMontage.m rename to src/plotting/createOverlayMontage.m index 1296d9b5..2897ef27 100644 --- a/createOverlayMontage.m +++ b/src/plotting/createOverlayMontage.m @@ -1,6 +1,6 @@ function output = createOverlayMontage(varargin) - % (C) Copyright 2022 bidspm developers + % (C) Copyright 2024 bidspm developers % fmrwhy_util_createOverlayMontage(tsnr_img{i}, overlayImg, 9, 1, '', ... % 'hot', 'off', 'max', [0 250], [33, 168, 10], tsnr_saveAss{i}); @@ -55,9 +55,7 @@ 'cxs', cxs); % Create figures with background montage and overlaid masks - f = figure('units', 'normalized', ... - 'outerposition', [0 0 1 1], ... - 'visible', visibility); + f = initMontageFigure(shape, visibility); imagesc(montage_template.whole_img); colormap(cmap); if ~isempty(cxs) @@ -77,7 +75,8 @@ if iscell(overlayImg) for i = 1:numel(overlayImg) - montage_overlay{i} = createMontage(overlayImg{i}, 'columns', columns, ... + montage_overlay{i} = createMontage(overlayImg{i}, ... + 'columns', columns, ... 'rotate', rotate, ... 'cmap', cmap, ... 'visibility', 'off', ... @@ -86,7 +85,8 @@ end else montage_overlay = {}; - montage_overlay{1} = createMontage(overlayImg, 'columns', columns, ... + montage_overlay{1} = createMontage(overlayImg, ... + 'columns', columns, ... 'rotate', rotate, ... 'cmap', cmap, ... 'visibility', 'off', ... @@ -103,7 +103,8 @@ bound_whole_bin = bwboundaries(montage_overlay{i}.whole_img); Nblobs_bin = numel(bound_whole_bin); for b = 1:Nblobs_bin - p = plot(ax, bound_whole_bin{b, 1}(:, 2), bound_whole_bin{b, 1}(:, 1), 'color', rbgclr, 'LineWidth', 1); + p = plot(ax, bound_whole_bin{b, 1}(:, 2), bound_whole_bin{b, 1}(:, 1), ... + 'color', rbgclr, 'LineWidth', 1); end end end diff --git a/src/plotting/initMontageFigure.m b/src/plotting/initMontageFigure.m new file mode 100644 index 00000000..38a43655 --- /dev/null +++ b/src/plotting/initMontageFigure.m @@ -0,0 +1,24 @@ +function f = initMontageFigure(shape, visibility) + % (C) Copyright 2024 bidspm developers + + scr_size = get(0, 'ScreenSize'); + dist = scr_size(4); + if scr_size(3) < dist + dist = scr_size(3); + end + % Create figure - outerposition = [left bottom width height] + + if strcmp(shape, 'max') + f = figure('visible', visibility, ... + 'units', 'normalized', ... + 'outerposition', [0 0 1 1]); + elseif strcmp(shape, 'square') + f = figure('visible', visibility, ... + 'units', 'pixels', ... + 'outerposition', [0 0 dist dist]); + else + f = figure('visible', visibility, ... + 'units', 'pixels', ... + 'outerposition', [0 0 dist dist]); + end +end diff --git a/untitled.m b/untitled.m index 893894ea..5c2c1a8a 100644 --- a/untitled.m +++ b/untitled.m @@ -3,9 +3,15 @@ bidspm_dir = '/home/remi/github/cpp-lln-lab/bidspm'; -overlay_img = fullfile(bidspm_dir, 'demos/MoAE/outputs/derivatives/bidspm-stats/sub-01/task-auditory_space-MNI152NLin6Asym_FWHM-8/mask.nii'); +demos_dir = fullfile(bidspm_dir, 'demos/MoAE/outputs/derivatives/'); -template_img = fullfile(bidspm_dir, 'demos/MoAE/outputs/derivatives/bidspm-preproc/sub-01/func/sub-01_task-auditory_space-MNI152NLin6Asym_desc-smth8_bold.nii'); +overlay_img = fullfile(demos_dir, ... + 'bidspm-stats/sub-01/task-auditory_space-MNI152NLin6Asym_FWHM-8/mask.nii'); + +template_img = fullfile( ... + demos_dir, ... + 'bidspm-preproc', 'sub-01', 'func', ... + 'sub-01_task-auditory_space-MNI152NLin6Asym_desc-smth8_bold.nii'); template_hdr = spm_vol(template_img); template = spm_read_vols(template_hdr(1)); @@ -14,4 +20,5 @@ mask = spm_read_vols(mask_hdr); % createMontage(template, 'shape', 'square'); -createOverlayMontage(template, mask, 'rgbcolors', [255, 0, 0], 'shape', 'square'); +createOverlayMontage(template, mask, 'rgbcolors', [255, 0, 0], ... + 'shape', 'square');