Skip to main content
. 2025 Sep 15;11(9):316. doi: 10.3390/jimaging11090316
Algorithm 1 Segment and Recover (SAR)
  • Input: 

    input image x, window size (wx,wy), matching threshold T, Base Detector BaseDetector(·).

  • Output: 

    robust detection D*, inpainted images and CAUTION

  •   1:

    procedure  Sar(x,wx,wy,T)

  •   2:

    am AdvPredictor(x,wx,wy,T)

  •   3:

    pm AdvDetector(x,am)

  •   4:

    x PixelRestoration(x,pm)

  •   5:

    D BaseDetector(x)

  •   6:

    if  a==True  then

  •   7:

          D*CAUTION

  •   8:

    else

  •   9:

          D*D

  • 10:

    end if

  • 11:

    return  D*

  • 12:

    end procedure

  •   

     

  • 13:

    procedure  AdvPredictor(x,wx,wy,T)

  • 14:

    fmFe(x)

  • 15:

    X,Y,_Shape(fm)

  • 16:

    amZeroArray[X, Y, N + 1]

  • 17:

    for each valid (i,j) do

  • 18:

          l,v Jpeg(fm[i:i+wx:j+wy])

  • 19:

          am[i:i+wx,j:j+wy]am[i:i+wx,j:j+wy]+v

  • 20:

    end for

  • 21:

    amBinarize(am, T, wx, wy)

  • 22:

    return  am

  • 23:

    end procedure

 
 
▹ Adversary detection (frontend)
▹ Adversary localization
▹ Broken pixel restoration (backend)
▹ Conventional detection
 
▹ Trigger a caution
 
 
 
 
 

 
▹ Extract feature map
▹ Get the shape of fm
▹ Initialization
▹ Every window location
 
 
 
▹ Binarization
 
 
 
 
  • 24:

    procedure  AdvDetector(x,am)

  • 25:

    segFastSamAutomaticMaskGenerator(x)

  • 26:

    L,T,R,BShape(seg, am)

  • 27:

    Abox1Area_Seg[L1,T1,R1,B1]

  • 28:

    Abox2Area_Am[L2,T2,R2,B2]

  • 29:

    for each valid Abox1 do

  • 30:

          for each valid Abox2 do

  • 31:

            Ainter(RinterLinter)×(BinterTinter)

  • 32:

            AunionAbox1+Abox2Ainter

  • 33:

            IoUAinterAunion

  • 34:

            if IoU<0.9 then

  • 35:

                 return 0

  • 36:

            else

  • 37:

                 pmBinarize(am)

  • 38:

                 return pm

  • 39:

            end if

  • 40:

        end for

  • 41:

    end for

  • 42:

    end procedure


▹ Extract segmentation layer by layer
▹Get the left, top, right, and bottom of seg
▹ Initialization area of segmentation
▹ Initialization area of adversarial patch map
▹ Every segmentation
▹ Every Am
▹ Area of intersection
▹ Area of union
▹ Calculate IoU
 
▹ No overlap
 
▹ Binarization
▹ Return patch map
 
 
 
 
  • 43:

    procedure  PixelRestoration(x,pm)

  • 44:

    while  iT  and n>0  do

  • 45:

          CH×W2×2CRH×W×C

  • 46:

          RH×W2×2CCH×W2×C

  • 47:

          RH×W2×2CRH×W2×2C

  • 48:

          CH×W2×2CRH×W2×C

  • 49:

          RH×W×CCH×W2×C

  • 50:

    end while

  • 51:

    return  x

  • 52:

    end procedure

 
 
 
▹ Apply real FFT to input tensor
▹ Concatenate real and imaginary parts
▹ Apply a convolution block in the frequency domain
 
 
▹ Apply an inverse transform to recover a spatial structure