SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]];PNGtoGray[filename_]:=Reverse[Map[Map[First,#]&,Import[filename,"Data"]]];GIFtoGray[filename_]:=255-Reverse[Map[Map[First,#]&,Import[filename,"Data"]]];showGrayImage[img_]:=Graphics[Raster[img/Max[img]],FrameFalse];showBinaryImage[img_]:=Graphics[Raster[img],FrameFalse];showBinaryOverlay[img_,mask_]:=Graphics[Raster[MapThread[MapThread[If[#21,{1,0,0},{#1,#1,#1}]&,{#1,#2}]&,{img,mask}]],FrameFalse];showGrayOverlay[img_,mask_]:=Graphics[{Raster[img/Max[img]],Raster[Map[Map[{#,0,0,If[#1,.5,0]}&,#]&,mask]]},FrameFalse];toBinary[x_,threshold_]:=If[x>threshold,1,0]getBinarizedImage[img_,threshold_]:=(toBinary[#,threshold]&/@((N@img〚#〛/255))&/@(Range[Length[img]]))