Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision da9badeb9444052b558b6b134b72df5fff0fc277 authored by liangzifei on 09 March 2022, 23:29:32 UTC, committed by GitHub on 09 March 2022, 23:29:32 UTC
Update README.md
1 parent f116deb
  • Files
  • Changes
  • 0360b4c
  • /
  • Code
  • /
  • MRH_trainingPrep.m
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:da9badeb9444052b558b6b134b72df5fff0fc277
directory badge
swh:1:dir:699a1ad78753f130bee0affcc069dad78b04ec02
content badge
swh:1:cnt:b4a605ceeba24c99ca7457fb25a11e86ca7e3ce2

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
MRH_trainingPrep.m
%  Training data generation
%  The data is prepared from inital analyzed format dMRI data and saved in .mat file.

% Input:
%
% folder_dwi: the location of dmri analyzed image.
% ---default: work_folder = ['.\Train_Data\Subj\'];
%halfsize_input : the patchsize preparison paramter.
% --- default=1 means the pathsize is 2*1+1 = 3
% stride: the sample location of the training coordinates within a 3D brain
% grid.
% --- default =20 means sample on point every 20 pixels
% (User can further exclude pixels that are cracked or missed in Histology, espcially void ventrical pixels,
% to mitigate these noisy pixels influence to succeeding network training). 
% fluo_img: histology images working as training target.

% Output(saved):
%
% data: is a 3x3xMxN matrix that for nerual network input.
% label: is a 3x3xN matrix that for neurual network training target.
%
% Usage: [data,label] = MRH_trainingG(['.\Train_Data'],3,20,['.\AllenPathology2P60.img'])
%  - Zifei Liang (zifei.liang@nyumc.org)
% Using code please refer our work: 
% Inferring Maps of Cellular Structures from MRI Signals using Deep Learning 
% https://www.biorxiv.org/content/10.1101/2020.05.01.072561v1

function [data,label] = MRH_trainingPrep(folder_dwi, halfsize_input, stride0, fluo_img)
% folder_dwi =['R:\zhangj18lab\zhangj18labspace\Zifei_Data\HCP\DeepNetIdea\JesseGray\JesseGray20191223\Porcessed\C'];
%% start loop %%%%%%%%%%%%%%%%
% halfsize_input = 1;
% size_label = 1;
% scale = 3;
% stride = 20;
file_list = dir(folder_dwi); file_list(1:2) = [];
count=0;
% sample_num=[1,2,4,5];
%% loop over all training subjects
for sample_img = 1:length(file_list)
    %dwi2000 is the diffusion data scanned from b=2000
    dwi2000 = load_untouch_nii([folder_dwi,file_list(sample_img).name,'\rigidaffine_Lddm_dwi2000.img']);
    % dwi5000 is diffusion b=5000 data
    dwi5000 = load_untouch_nii([folder_dwi,file_list(sample_img).name,'\rigidaffine_Lddm_dwi5000.img']);
    t2MTONOFF = load_untouch_nii([folder_dwi,file_list(sample_img).name,'\rigidaffine_lddm_t2MTONOFF.img']);
    fa_img = load_untouch_nii([folder_dwi,file_list(sample_img).name,'\rigidaffine_Lddm_fa.img']);
    fa_mask = load_untouch_nii([folder_dwi,file_list(sample_img).name,'\Masked_outline.img']);
    
    % all MRI and AllenPathology registered in P60 here one target is used
    % as example. Please replace by self defined histology, for any other
    % data. voxel-wise data preparison dose not change pixel-wise
    % information by warping from subject to P60 template space.
%     fluo_img = load_untouch_nii(['R:\zhangj18lab\zhangj18labspace\Zifei_Data\HCP\DeepNetIdea\Allen_fluorescence',...
%         '\AllenPathology2TanzilP60.img']);
    %'\mean10_data',num2str(sample_img),'.img']);
    
    % preprocess data before sampling. 
    dwi_data = cat(4,dwi2000.img,dwi5000.img,t2MTONOFF.img);
    fa_data=fa_img.img; fa_data(isnan(fa_data))=0; dwi_data(isnan(dwi_data))=0;
    mask_data = fa_mask.img; mask_data(isnan(mask_data))=0;
    fluo_data = fluo_img.img; fluo_data(isnan(fluo_data))=0;
    
    dwi_data=permute(dwi_data,[1,3,2,4]); fa_data=permute(fa_data,[1,3,2]);
    mask_data = 1- permute(mask_data,[1,3,2]); fluo_data = permute(fluo_data,[1,3,2]);
    
    dwi_data=double(dwi_data);%./double(max(max(max(max(max(dwi_data))))));
    fa_data=double(fa_data);%./double(max(max(max(max(max(fa_data))))));
    
    [A,B,C,D]=size(dwi_data);
    figure;subplot(1,2,1);imshow(fluo_data(:,:,124),[]); subplot(1,2,2);imshow(fa_data(:,:,124),[]);
    %clear dwi_img fa_img;
    [hei,wid,C,channel]=size(dwi_data);
    %% loop count samples %%%%%%%%%%%%%%%%%%%%%%%%%
    % 118:159---jplease change to coregistered MRI and histology slice numbers 
    for slice=118:159
        % sample training patches that are rational, we use fa data as a
        % reference, USER can define by self. 
        tempt = fa_data(:,:,slice);
        temp=tempt(tempt>102);
        sum_temp=sum(logical(temp));
        % stride refined to larger steps for slices contains more blank
        % background. small steps for less background slices.
        if sum_temp>1000
            stride = 6;
        elseif sum_temp<40000
            stride = 8;
        else 
            stride = stride0;
        end
        
        for x = 1+halfsize_input : stride : hei-halfsize_input
            for y = 1+halfsize_input :stride : wid-halfsize_input
                % include all MRI contrasts [1:end], USER can select input
                % channels want to use here
                subim_input = dwi_data(x-halfsize_input : x+halfsize_input, y-halfsize_input : y+halfsize_input,slice,[1:end]);
                %% only diffusion MRI %%%%%%%%%%%%%%%%%%%%%%%%%
                subim_label = fluo_data(x-halfsize_input : x+halfsize_input, y-halfsize_input : y+halfsize_input,slice);
                flag = sum(sum(sum(subim_label))); sum_fa=sum(sum(sum(sum(logical(subim_label)))));
                % set registration to samples. here sample unit FA >=
                % 4. mask > 0. Patch non-zero value >= 30
                if (flag<30||isnan(flag)||sum_fa<4||mask_data(x,y,slice))
                    continue;
                else
                    count=count+1
                    data(:, :, :, count) = permute(subim_input,[1,2,4,3]);
                    label(:, :, :, count) = subim_label;
                end
            end
        end
    end
end
% arrange the training patches in random oder.
order = randperm(count);
data = data(:, :, :,order);
label = label(:, :,:,  order);
save traindata.mat data label -v7.3;
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API