File: imgutil.pas

package info (click to toggle)
mricron 0.20140804.1~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,508 kB
  • sloc: pascal: 114,876; sh: 49; makefile: 35
file content (85 lines) | stat: -rwxr-xr-x 3,052 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
unit imgutil;
{$H+}
interface

function UnscaledMean (lOverlayNum: integer): double;
function ScaledMean (lOverlayNum: integer): double;
procedure BatchChangeInterceptSoVOIEqualsZero;


implementation
uses text,nifti_hdr,nifti_hdr_view,define_types,nifti_img, nifti_img_view, nifti_types;


function UnscaledMean (lOverlayNum: integer): double;
//kVOIOverlayNum
var
	lROIVol,lInc: integer;
  lROISum: double;
begin //proc ShowDescript
   result := 0;
   if gMRIcroOverlay[lOverlayNum].ScrnBufferItems <> gMRIcroOverlay[kBGOverlayNum].ScrnBufferItems then
      exit;
		lROIVol := 0;
		lROISum := 0;
	for lInc := 1 to gMRIcroOverlay[lOverlayNum].ScrnBufferItems do begin
		if gMRIcroOverlay[lOverlayNum].ScrnBuffer^[lInc] > 0 then begin
		  lROISum := lROISum + RawBGIntensity(lInc);
      inc(lROIVol);
    end;
	end; //for each voxel
  if lROIVol > 0 then
    result := lROISum/lROIVol;
end;

function ScaledMean (lOverlayNum: integer): double;
begin
  result := UnscaledMean(lOverlayNum);
  result := Raw2ScaledIntensity (gMRIcroOverlay[kBGOverlayNum],result);
end;

procedure BatchChangeInterceptSoVOIEqualsZero;
var
	lInc,lNumberofFiles,lMinClusterSz: integer;
  lZeroHdr : TNIfTIHdr;
  lFilename,lVOIname:string;
  lPref: boolean;
  lMean: double;
begin
  for lInc := 1 to (knMaxOverlay-1) do
	    FreeImgMemory(gMRIcroOverlay[lInc]);
  ImgForm.UpdateLayerMenu;

  if not OpenDialogExecute(kImgPlusVOIFilter,'Select volume of interest',false) then exit;
  lVOIName := HdrForm.OpenHdrDlg.FileName;
  if not OpenDialogExecute(kImgFilter,'Select perfusion images',true) then exit;
  lNumberofFiles:= HdrForm.OpenHdrDlg.Files.Count;
  if  lNumberofFiles < 1 then
    exit;
  TextForm.MemoT.Lines.Clear;
  lPref := gBGImg.ResliceOnLoad;
  gBGImg.ResliceOnLoad := false;
  for lInc:= 1 to lNumberofFiles do begin
            lFilename := HdrForm.OpenHdrDlg.Files[lInc-1];
            ImgForm.OpenAndDisplayImg(lFilename,false);
            ImgForm.OverlayOpenCore ( lVOIname, kVOIOverlayNum);
            lMean := UnscaledMean(kVOIOverlayNum);
              lZeroHdr := gMRIcroOverlay[kBGOverlayNum].NIFTIhdr;
            if lZeroHdr.scl_slope <> 1 then
              TextForm.MemoT.Lines.Add(lFilename+'  Scale slope is not 1, please contact Chris Rorden ')
            else if lMean <> 0 then begin
              TextForm.MemoT.Lines.Add(lFilename+kTextSep+realtostr(lMean,5));
              lZeroHdr.scl_inter := lZeroHdr.scl_inter - lMean;
		          lFilename := changefileprefix(lFilename,'z');
              SaveAsVOIorNIFTIcore (lFilename, gMRIcroOverlay[kBGOverlayNum].ImgBuffer,gMRIcroOverlay[kBGOverlayNum].ImgBufferItems,gMRIcroOverlay[kBGOverlayNum].ImgBufferBPP,1,lZeroHdr)
            end else
              TextForm.MemoT.Lines.Add(lFilename+'  UNCHANGED (mean of VOI is already zero) ');

            //FindClustersText(gMRIcroOverlay[kBGOverlayNum], lThresh,lMinClusterSz);
  end;//lLoop
  gBGImg.ResliceOnLoad := lPref;
  TextForm.Show;
end;


end.