mne-tools / mne-tools/mne-python
Area of a label
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
I am wondering, anyone aware of a function, that can estimate label area ?
In Matlab I used to do this as follows:
`function area = triangle_area(faces,verts)
r12 = verts(faces(:,1),:);
r13 = verts(faces(:,3),:) - r12;
r12 = verts(faces(:,2),:) - r12;
area = sqrt(sum(cross(r12',r13').^2,1))/2;
return
function c = cross(a,b)
c = [a(2,:).*b(3,:)-a(3,:).*b(2,:)
a(3,:).*b(1,:)-a(1,:).*b(3,:)
a(1,:).*b(2,:)-a(2,:).*b(1,:)];
return`
`function [PFV,PF]=convert_patch(P,FV,F)
% function [PFV]=convert_patch(P,FV)
% -------------------------------------------------------------
% Given a list of connected nodes (P), gives the structure Faces Vertices of the
% patch
% --------------------------------------------------------------
%
% INPUTS :
% - P : indices of connected nodes
% - FV : structure with fields faces, vertices ,i.e. corresponding to a
% tesselation
% - F : scalar field defined on nodes of FV
% OUTPUTS :
% - PFV : subtesselation of FV based on the nodes P with fields faces,
% vertices
% - PF : scalar field defined on the resulting submesh
% -------------------------------------------------------------------
PFV.vertices=FV.vertices(P,:);
PF=zeros(length(P),size(F,2));
T=[];
nT=1;
for ii=1:size(P,1)
[ind_i,ind_j]=find(FV.faces==P(ii));
for k=1:length(ind_i)
if ismember(ind_i(k),T)
else
convtri=convert(FV.faces(ind_i(k),:),P);
if length(convtri)<=2
else
PFV.faces(nT,:)=convtri;
T=[ind_i(k) T];
nT=nT+1;
end
end
end
PF(ii,:)=F(P(ii),:);
end
function [convtri]=convert(tri,P)
ind1=find(P==tri(1));
ind2=find(P==tri(2));
ind3=find(P==tri(3));
convtri=[ind1 ind2 ind3];`
`% Need freesurfer matlab toolbox
addpath /freesurfer/matlab/
% here provide the surface file you want
[vertices_l, faces_l] = freesurfer_read_surf('lh.pial');
[vertices_r, faces_r] = freesurfer_read_surf('rh.pial');
faces_l=faces_l+1;
faces_r=faces_r+1;
% Computing area in mm2 of the whole brain
area_l =triangle_area(faces_l,vertices_l);
area_r =triangle_area(faces_r,vertices_r);
label_file='xx-lh.label';
labverts = read_label('',label_file);% freesurfer function
labverts = 1+squeeze(labverts(:,1));
FV.faces=faces_l;
FV.vertices=vertices_l;
[PFV,PF]=convert_patch(labverts,FV,zeros(size(vertices_l,1)),1);
area_l_label =triangle_area(PFV.faces,PFV.vertices);`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the MATLAB triangle_area and convert_patch examples in the issue, along with the FreeSurfer surface and label workflow they use. No Python file, test, or MNE entry point is named, so the desired API and implementation location need to be established first. Done should define and support label-area estimation in the Python project with tests for the relevant surface and label inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matlab, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100