pro tripletfiles,Log ; PC Version ; Mod 2004.01.12, CSee, Default \DB2 if available. ;This program makes jpeg and png files of the image in the current Log ; (along with its corrispoding triplet mates). ;This version also works on \DB2 - Mike Bushroe's images ;It also created Histogram Equilized png's ;The streach on the jpeg is min-to-2.5*mean ;The streach on the pngs is min-to-mean+4sigma (square rooted) or max whichever is less. ;The output file is: Log\Triplets2\jpg or \png or \histeq cd,'',current=cdir & cd,cdir if n_params() eq 0 then begin Print,string(10b),"Please indicate the Log directory (i.e. the directory below 'Log')" log = dialog_pickfile(path='c:\',/directory) endif print,'' print,'The Test Log is: ',log ;____________________________________________________________________________ ;check to see if Bushroe's processor has been run on this log. db='DB' file_ck=findfile(log+'DB2') if file_ck(0) ne '' then db='DB2' Print,'Using: ',db wait,1 ;;if file_ck(0) ne '' then begin ;i.e. \DB2 does exist ;;ans='n' ;;read,'Do you want to use the images in \DB2 (Bushroe Processed)? (y or n): ',ans ;;if ans eq 'y' then begin & print,'using \DB2' & db='DB2' & endif else print,'using \DB' ;;endif ;Create the output directories... if db eq 'DB' then directory='Triplets' else directory='Triplets2' Output=t_mkdir(Log+directory) Output=t_mkdir(Log+directory+'\jpeg') Output=t_mkdir(Log+directory+'\png') Output=t_mkdir(Log+directory+'\histeq') ;____________________________________________________________________________ ;List Files... cd,Log+db+'\Image' files=t_getfil('*.*') ;spawn,'lsf',files,/noshell s=size(files) nfiles=fix(s(1)) numfiles=sstr(nfiles) ;numfiles=short string (nfiles) if files(0) eq '' then begin & print,'No files found' & goto,exit & endif array_sort,files ;sorts files in assending order print,'The number of Images in this log is: ',sstr(nfiles),' (1 thru ',sstr(nfiles),')' print,'Working, please wait...' ;____________________________________________________________________________ ;Initalize... auto=1 ;for auto=1 tvscl min=0 ;the tvscl min setting max=4095 ;the tvscl max setting ilast=0 ;ilast is the previous value of i space=1.5 ;x spacing in inches sf=.75 ;scale factor (scales the size of the images on the page) ypos=0.5 ;sets the y position for each row ff=-1 ;flag for flat fields, 1=>enabled, -1=>disabled p0=intarr(176,256) ;MRI frame 176x256 or 254 p1=intarr(128,256) ;SLI frame 128x256 or 254 p2=intarr(160,256) ;HRI frame 160x256 or 254 hight=[256,256,256] ;hight of the three images n=1 ;next file to use counter dot='.' again: ;print,dot,format='($,a1)' ;____________________________________________________________________________ ;find three matching files... filetime=strmid(files(n),13,13) ;stop triplet_files=t_getfil('*'+filetime+'*') & siz=size(triplet_files) & nfiles2=siz(1) imno=intarr(3) ;actual image number from file name for i=0,nfiles2-1 do imno(i)=fix(strmid(triplet_files(i),2,5)) if nfiles2 ne 3 then print,'Not a complete triplet',imno array_sort,triplet_files ;sorts files in assending order for i=0,nfiles2-1 do begin d_read,triplet_files(i),h,p ;read in each image in order s=size(p) hight(i)=s(2) type=d_value(h,96) ;21=MRI,22=SLI, 23=HRI case type of 21: p0=p 22: p1=p 23: p2=p else:print,'type of ',triplet_files(i),' is unknown',type endcase endfor ;____________________________________________________________________________ ;condition data... ;remove hot pixels & cosmic rays (less than 15 pixels greater that 6 sigma) index=where(p0 gt mean(p0)+6.*stdev(p0)) if index(0) ne -1 then begin siz=size(index) if siz(1) le 15 then p0(index)=Max(p0(where(p0 le mean(p0)+6.*stdev(p0)))) endif index=where(p1 gt mean(p1)+6.*stdev(p1)) if index(0) ne -1 then begin siz=size(index) if siz(1) le 15 then p1(index)=Max(p1(where(p1 le mean(p1)+6.*stdev(p1)))) endif index=where(p2 gt mean(p2)+6.*stdev(p2)) if index(0) ne -1 then begin siz=size(index) if siz(1) le 15 then p2(index)=Max(p2(where(p2 le mean(p2)+6.*stdev(p2)))) endif ;;scale each from 0 min to 4095 max (skip if all zeros = missing image)... ;if mean(p0) ne 0 then p0=(P0-min(p0))*4095./(max(p0)-min(p0)) ;if mean(p1) ne 0 then p1=(p1-min(p1))*4095./(max(p1)-min(p1)) ;if mean(p2) ne 0 then p2=(p2-min(p2))*4095./(max(p2)-min(p2)) ;scale so that their means are equal... ;equilize images to the mean of the brightest... q=max([mean(p0),mean(p1),mean(p2)]) if mean(p0) ne 0 then p0=p0*q/mean(p0) if mean(p1) ne 0 then p1=p1*q/mean(p1) if mean(p2) ne 0 then p2=p2*q/mean(p2) ;____________________________________________________________________________ ;combine images into triplet (pt)... pt=intarr(176,768) ;Frame to hold the triplet iface1=hight(0) ;SLI-MRI interface hight iface2=hight(0)+hight(1) ;MRI-HRI interface hight iface3=hight(0)+hight(1)+hight(2) ;bottom of HRI pt(24:151,0:iface1-1)=p1(*,0:hight(0)-1) ;SLI pt(0:175,iface1:iface2-1)=p0(*,0:hight(1)-1) ;MRI pt(8:167,iface2:iface3-1)=p2(*,0:hight(2)-1) ;HRI pt(where(pt eq 0))=min(pt(where(pt ne 0))) ;set all 'empty' pixels to the min of the data pt=rotate(pt,2) ;right side up ;____________________________________________________________________________ ;write triplets to disk... ;1-jpeg with 2.5xAve stretch ;stop pout=bytscl(pt,min=min(pt),max=2.5*mean(pt)0 maxpt=max(pout2) peq=hist_equal(pout2,minv=minpt,maxv=maxpt,top=255) outfile2=Log+directory+'\histeq\triplet_histeq.'+sstr(imno(0))+'.jpg' write_jpeg,outfile2,peq,quality=100 ;3-png with square root stretch pout3=pt^.5 pout3=pout3*21845.0/mean(pout3) ;scale average up to 1/3 of 16 bits sigma3=stdev(pout3,avep3) index=where(pout3 gt avep3+4.*sigma3) ;;print,min(pout3),avep3,max(pout3),sigma3 if index(0) eq -1 then goto,skip2 pout3(index)=max(pout3(where(pout3 le avep3+4.*sigma3))) ;chops off histogram above 4 sigma skip2: minpt=min(pout3)>0 maxpt=max(pout3) p_png=uint(65535d0*(double(pout3)-double(minpt))/(double(maxpt)-double(minpt))) outfile3=Log+directory+'/png/triplet.'+sstr(imno(0))+'.png' write_png,outfile3,p_png ;;print,minpt,mean(pout3),maxpt,stdev(pout3) n=n+nfiles2 ;add the number of files used to the count if n lt nfiles then goto,again ;if not all files are read, then keep going... exit: Print,'Done!' cd,Log end