Skip to content
Snippets Groups Projects
Commit 58f35d6b authored by Maria Engel's avatar Maria Engel
Browse files

Initial commit

parent b8ff273b
No related branches found
No related tags found
1 merge request!1Initial commit
function [packingDensity, L_optimum, isDegenerate, packingDensityCAIPI, L_CAIPI] = ...
ComputeMostHexagonalSampling(R_inplane, FOV_inplane, sliceSpacing, nSlicesSimultaneously, ...
nSlicesTotal, sliceThickness, sliceGap, doPlot, doDebug, gifName)
% This function computes how to optimally sample the phase encoding plane for 3D/Multiband
% EPI/Spiral to achieve the maximum packing density of circles in the image domain
%
% IN
% R_inplane in-plane undersampling factor
%
% FOV_inplane in-plane FOV
% [same unit as sliceSpacing, sliceThickness & sliceGap]
%
% sliceSpacing distance between simultaneously excited slices
% (only used if all input arguments available)
% [same unit as FOV_inplane, sliceThickness & sliceGap]
%
% nSlicesSimultaneously number of simultaneously excited slices
% (only needed if sliceSpacing empty)
%
% nSlicesTotal total number of slices
% (only needed if sliceSpacing empty)
%
% sliceThickness slice thickness
% (only needed if sliceSpacing empty)
% [same unit as FOV_inplane, sliceSpacing & sliceGap]
%
% sliceGap gap between slices
% (only needed if sliceSpacing empty)
% [same unit as FOV_inplane, sliceSpacing & sliceThickness]
%
% doPlot Plot grid and packing density curve {false}
%
% doDebug Plot all intermediate grids that are being tested {false}
%
% gifName name of gif in case debug plot should be saved as gif
%
%
% OUT
% packingDensity circle packing density [%]
%
% L_optimum Optimum choice of L
% (maximising packing density = most homogeneous sampling distribution)
%
% isDegenerate flag whether packing density metric is degenerate
%
%
% Example: [packingDensity, L_optimum] = ComputeMostHexagonalSampling(1, 192, 19.2, 3);
% [packingDensity, L_optimum] = ComputeMostHexagonalSampling(1, 192, [], 3, 3, 4, 15.2)
%
% Author: Maria Engel
% (c) Cardiff University Brain Research Imaging Centre (CUBRIC), Cardiff University, United Kingdom
if nargin == 7
sliceSpacing = nSlicesTotal*(sliceThickness+sliceGap)/nSlicesSimultaneously;
end
if nargin < 8
doPlot = false;
end
if nargin < 9
doDebug = false;
end
if nargin < 10
gifName = [];
end
% in-plane spacing of lines in k-space
deltak_inplane = 2*pi*R_inplane/FOV_inplane;
kzSlabThickness = 2*pi/sliceSpacing;
% As soon as L is so large that the distance to the chronologically next point is smaller than to
% the next point after a down-blip, the grids are going to get only worse = less homogeneous, i.e.
% no point in checking their packing density
Lmax = ceil(sqrt(0.5+sqrt(0.25+(kzSlabThickness/deltak_inplane)^2)));
% For L<2 there is an L>2 which produces a rotationally symmetric grid i.e. same packing density
Lmin = 2;
Lincrement = 0.01;%0.001;
LArray = Lmin:Lincrement:Lmax;
% Make sure you include cases shown in Narsude et al. MRM 2016, e.g. Fig 1d
% They use DELTA rather than L and propose integer DELTA
DELTA = 1:nSlicesSimultaneously;
% Translate these DELTA's to L's and find which ones present unique patterns (i.e. not yet covered
% by the previous L's)
LNarsudeUnique = nSlicesSimultaneously./DELTA;
LNarsudeUnique = LNarsudeUnique(mod(LNarsudeUnique,1)~=0);
LNarsudeUnique = LNarsudeUnique(LNarsudeUnique>2);
LArray = sort([LArray LNarsudeUnique]);
howFar2Look = 10; % TODO: Find out what to put here!
d_min = zeros(size(LArray));
if doDebug
figure('Name','Sampling grid and alps');
ah = subplot(1,2,1);
end
%% Initiate arrays
packingDensityArray = zeros(numel(LArray),1);
isBlippedCAIPI = zeros(numel(LArray),1);
isNarsude = zeros(numel(LArray),1);
%% Go through range of L's, compute the minimum distance between grid points and the resulting packing density
for iL = 1:numel(LArray)
[kyArray, kzArray] = GetGridPoints(howFar2Look*ceil(LArray(iL)),deltak_inplane,sliceSpacing,LArray(iL));
d = sqrt(kyArray.^2 + kzArray.^2);
d_min(iL) = min(d(d>0));
packingDensityArray(iL) = pi/4*d_min(iL)^2/(2*pi*deltak_inplane/sliceSpacing);
isBlippedCAIPI(iL) = ceil(LArray(iL))==LArray(iL);% && LArray(iL)<=nSlicesSimultaneously; % This is being kind to blipped CAIPIRINHA!
isNarsude(iL) = ismember(LArray(iL), LNarsudeUnique);
if doDebug
[kyArray, kzArray] = GetGridPoints(3*Lmax, deltak_inplane, sliceSpacing, LArray(iL));
PlotGrid(kyArray, kzArray, sliceSpacing, ah);
subplot(1,2,2); hold on;
plot(LArray(iL),packingDensityArray(iL)*100,'.','Color','k');
if isBlippedCAIPI(iL) || isNarsude(iL)
plot(LArray(iL),packingDensityArray(iL)*100,'x','Color','r','MarkerSize',10,'LineWidth',3);
end
xlabel('L'); ylabel('Packing density [%]');
xlim([Lmin Lmax]); ylim([min(packingDensityArray*100) 90.7]);
sgtitle(sprintf('L = %.2f',LArray(iL)));
%% Make GIF
if ~isempty(gifName)
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if iL == 1
imwrite(imind,cm,gifName,'gif', 'Loopcount',inf,"DelayTime",0.1);
else
imwrite(imind,cm,gifName,'gif','WriteMode','append',"DelayTime",0.1);
end
end
end
end
%% Find the L that maximizes the packing density
[d_optimum, ind_optimum] = max(d_min);
L_optimum = LArray(ind_optimum);
isDegenerate = d_optimum > kzSlabThickness;
packingDensity = ComputePackingDensity(d_optimum, deltak_inplane, sliceSpacing);
%% Compute options that blipped-CAIPIRINHA would offer
indCAIPI = find(isBlippedCAIPI + isNarsude);
d_CAIPI = d_min(indCAIPI);
L_CAIPI = LArray(indCAIPI);
packingDensityCAIPI = ComputePackingDensity(d_CAIPI,deltak_inplane,sliceSpacing);
%% Plot grid and resulting sampling density for all options
if doPlot
% For plotting get grid points on a bit larger range
[kyArray, kzArray] = GetGridPoints(2*ceil(Lmax), deltak_inplane, sliceSpacing, L_optimum);
PlotGrid(kyArray, kzArray, sliceSpacing);
figure('Name','Packing density'); hold on;
plot(LArray, packingDensityArray*100);
plot(L_CAIPI, packingDensityCAIPI*100, 'x', 'MarkerSize', 10, 'LineWidth', 3);
xlabel('L');
ylabel('Packing density [%]');
end
end
%% Compute coordinates of grid points for a given sampling scheme
function [kyArray, kzArray] = GetGridPoints(mRange,deltak_inplane,sliceSpacing,L)
% Get grid points in PE plane for given sampling pattern
mArray = -mRange:mRange;
kyArray = mArray.*deltak_inplane;
kzArray = 2*pi/sliceSpacing*(mArray./L-floor(mArray./L));
end
%% Plot grid from given coordinates of grid points
function ah = PlotGrid(ky,kz,sliceSpacing,ah)
if nargin < 4 || isempty(ah)
figure('Name', 'Sampling grid');
else
axes(ah);
end
scatter(ky, kz, 'MarkerEdgeColor', [0.5 0.5 0.5], 'MarkerFaceColor', [0.5 0.5 0.5], 'LineWidth', 5);
hold on;
yline(0,'r','LineWidth',3);
yline(2*pi/sliceSpacing,'r','LineWidth',3);
axis equal;
ylim(2*pi/sliceSpacing*[-1 2]);
xlim([min(ky) max(ky)]);
xlabel('k_y'); ylabel('k_z');
hold off;
end
%% Compute packing density for a given smallest distance d in a grid
function packingDensity = ComputePackingDensity(d, deltak_inplane, sliceSpacing)
A_circle = pi/4*d.^2;
A_unitcell = 2*pi*deltak_inplane/sliceSpacing;
packingDensity = A_circle/A_unitcell;
end
\ No newline at end of file
clear all;
baseFolder = pwd;
doSave = true;
if doSave
gifName = fullfile(baseFolder,'GridAndAlpsGif.gif');
else
gifName = [];
end
Nsim = 6;
R = 1;
FOVinplane = 220;
sliceSpacing = FOVinplane/2/Nsim;
[packingDensity, L_optimum, isDegenerate, packingDensityCAIPItmp, L_CAIPItmp] = ...
ComputeMostHexagonalSampling(R, FOVinplane, sliceSpacing, Nsim, [], [], [], [], true, gifName);
[packingDensityCAIPI, indCAIPI] = max(packingDensityCAIPItmp);
L_CAIPI = L_CAIPItmp(indCAIPI);
clear all;
% # simultaneously excited slices to be investigated
NSimArray = 2:8;
% Range of total undersampling factors to be investigated
Rtot_start = 1;
Rtot_end = 12;
Rtot_increment = 0.001;
FOVinplane = 220;
doSave = true;
saveFolder = pwd;
if doSave
dfws = get(0,'DefaultFigureWindowStyle');
set(0,'DefaultFigureWindowStyle','normal');
end
fh = figure('Name','Packing density'); hold on;
t = tiledlayout(numel(NSimArray),1,'TileSpacing','Compact');
for iNSim = 1:numel(NSimArray)
Nsim = NSimArray(iNSim);
clear RArray packingDensity L_optimum packingDensityCAIPI L_CAIPI
RArray = (Rtot_start/Nsim):Rtot_increment:ceil(Rtot_end/Nsim);
sliceSpacing = FOVinplane/2/Nsim;
for iR = 1:numel(RArray)
[packingDensity(iR), L_optimum(iR), isDegenerate, packingDensityCAIPItmp, L_CAIPItmp] = ...
ComputeMostHexagonalSampling(RArray(iR), FOVinplane, sliceSpacing, Nsim);
[packingDensityCAIPI(iR), indCAIPI] = max(packingDensityCAIPItmp);
L_CAIPI(iR) = L_CAIPItmp(indCAIPI);
if isDegenerate
break
end
end
%%
if numel(RArray)>1
if doSave
name = [];
else
name = sprintf(', N_{sim} = %i',Nsim);
end
nexttile; hold on;
plot(RArray(1:numel(packingDensity))*Nsim,packingDensity*100,...
'DisplayName', ['As hexagonal as possible' name],'LineWidth',2,'Color','k');
plot(RArray(1:numel(packingDensity))*Nsim,packingDensityCAIPI*100,...
'DisplayName',['Blipped CAIPIRINHA' name],'LineWidth',2)
yline(pi/2/sqrt(3)*100,'Color',[0.5 0.5 0.5],'LineWidth',2,'DisplayName', 'Maximum circle packing density, 90.7%');
xlim([Rtot_start Rtot_end]);
ylim([60 92]);
if iNSim==numel(NSimArray) || doSave==false
xlabel('R_{total}');
legend;
else
xlabel(''); xticks('');
end
end
end
if numel(RArray)>1
ylabel(t,'Packing density [%]')
end
if doSave
set(fh,'Position',[488.2 61.8 520.8 700])
hLegend = findobj(gcf, 'Type', 'Legend');
hLegend.Position = [0.476 0.834 0.421 0.062];
export_fig(fullfile(saveFolder, 'PackingDensityOverR'),'-png','-transparent','-a1','-r300',gcf);
set(0,'DefaultFigureWindowStyle',dfws);
end
\ No newline at end of file
# HexagonalSampling
This repository contains code to find the optimum sampling for 3D/Multiband sampling in MRI using EPI or Spirals.
ISMRM abstract Engel et al. 2024
## Getting started
Reproduce results in abstract by running
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git.cardiff.ac.uk/sapme1/hexagonalsampling.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.cardiff.ac.uk/sapme1/hexagonalsampling/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
MakeGridAndAlpGif.m (for Gif 1)
## License
For open source projects, say how it is licensed.
and
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
MakeOptDvsRPlot.m (for Figure 2, this requires https://se.mathworks.com/matlabcentral/fileexchange/23629-export_fig)
\ No newline at end of file
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