LPX commited on
Commit
62c8661
·
1 Parent(s): 6909ab7

feat: add Bit Plane extraction to forensic analysis and enhance Gradio interface with new processing tools

Browse files
Files changed (1) hide show
  1. app_mcp.py +49 -10
app_mcp.py CHANGED
@@ -362,6 +362,8 @@ def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_d
362
  # 6. Perform forensic processing
363
  gradient_image = gradient_processing(img_np_og) # Added gradient processing
364
  minmax_image = minmax_preprocess(img_np_og) # Added MinMax processing
 
 
365
 
366
  # First pass - standard analysis
367
  ela1 = ELA(img_np_og, quality=75, scale=50, contrast=20, linear=False, grayscale=True)
@@ -370,7 +372,7 @@ def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_d
370
  ela2 = ELA(img_np_og, quality=75, scale=75, contrast=25, linear=False, grayscale=True)
371
  ela3 = ELA(img_np_og, quality=75, scale=75, contrast=25, linear=False, grayscale=False)
372
 
373
- forensics_images = [img_pil, ela1, ela2, ela3, gradient_image, minmax_image]
374
 
375
  # 7. Generate boilerplate descriptions for forensic outputs for anomaly agent
376
  forensic_output_descriptions = [
@@ -379,7 +381,8 @@ def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_d
379
  "ELA analysis (Pass 2): Grayscale error map, quality 75, enhanced contrast.",
380
  "ELA analysis (Pass 3): Color error map, quality 75, enhanced contrast.",
381
  "Gradient processing: Highlights edges and transitions.",
382
- "MinMax processing: Deviations in local pixel values."
 
383
  ]
384
  # You could also add descriptions for Wavelet and Bit Plane if they were dynamic outputs
385
  # For instance, if wavelet_blocking_noise_estimation had parameters that changed and you wanted to describe them.
@@ -581,14 +584,50 @@ with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ ov
581
  description="Extracts and visualizes individual bit planes from different color channels. This forensic tool helps identify hidden patterns and artifacts in image data that may indicate manipulation. Different bit planes can reveal inconsistencies in image processing or editing.",
582
  api_name="tool_bitplane"
583
  )
584
- # with gr.Tab("EXIF Full Dump"):
585
- # gr.Interface(
586
- # fn=exif_full_dump,
587
- # inputs=gr.Image(type="pil"),
588
- # outputs=gr.JSON(),
589
- # description="Extract all EXIF metadata from the uploaded image."
590
- # )
591
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  # --- MCP-Ready Launch ---
593
  if __name__ == "__main__":
594
  # Initialize CommitScheduler
 
362
  # 6. Perform forensic processing
363
  gradient_image = gradient_processing(img_np_og) # Added gradient processing
364
  minmax_image = minmax_preprocess(img_np_og) # Added MinMax processing
365
+ bitplane_image = bit_plane_extractor(img_np_og)
366
+
367
 
368
  # First pass - standard analysis
369
  ela1 = ELA(img_np_og, quality=75, scale=50, contrast=20, linear=False, grayscale=True)
 
372
  ela2 = ELA(img_np_og, quality=75, scale=75, contrast=25, linear=False, grayscale=True)
373
  ela3 = ELA(img_np_og, quality=75, scale=75, contrast=25, linear=False, grayscale=False)
374
 
375
+ forensics_images = [img_pil, ela1, ela2, ela3, gradient_image, minmax_image, bitplane_image]
376
 
377
  # 7. Generate boilerplate descriptions for forensic outputs for anomaly agent
378
  forensic_output_descriptions = [
 
381
  "ELA analysis (Pass 2): Grayscale error map, quality 75, enhanced contrast.",
382
  "ELA analysis (Pass 3): Color error map, quality 75, enhanced contrast.",
383
  "Gradient processing: Highlights edges and transitions.",
384
+ "MinMax processing: Deviations in local pixel values.",
385
+ "Bit Plane extractor: Visualization of individual bit planes from different color channels."
386
  ]
387
  # You could also add descriptions for Wavelet and Bit Plane if they were dynamic outputs
388
  # For instance, if wavelet_blocking_noise_estimation had parameters that changed and you wanted to describe them.
 
584
  description="Extracts and visualizes individual bit planes from different color channels. This forensic tool helps identify hidden patterns and artifacts in image data that may indicate manipulation. Different bit planes can reveal inconsistencies in image processing or editing.",
585
  api_name="tool_bitplane"
586
  )
587
+ with gr.Tab("Error Level Analysis (ELA)", visible=False):
588
+ gr.Interface(
589
+ fn=ELA,
590
+ inputs=[
591
+ gr.Image(type="pil", label="Input Image"),
592
+ gr.Slider(1, 100, value=75, step=1, label="JPEG Quality"),
593
+ gr.Slider(1, 100, value=50, step=1, label="Output Scale (Multiplicative Gain)"),
594
+ gr.Slider(0, 100, value=20, step=1, label="Output Contrast (Tonality Compression)"),
595
+ gr.Checkbox(value=False, label="Use Linear Difference"),
596
+ gr.Checkbox(value=False, label="Grayscale Output")
597
+ ],
598
+ outputs=gr.Image(type="pil"),
599
+ title="Error Level Analysis (ELA)",
600
+ description="Performs Error Level Analysis to detect re-saved JPEG images, which can indicate tampering. ELA highlights areas of an image that have different compression levels.",
601
+ api_name="tool_ela"
602
+ )
603
+ with gr.Tab("Gradient Processing", visible=False):
604
+ gr.Interface(
605
+ fn=gradient_processing,
606
+ inputs=[
607
+ gr.Image(type="pil", label="Input Image"),
608
+ gr.Slider(0, 100, value=90, step=1, label="Intensity"),
609
+ gr.Dropdown(["Abs", "None", "Flat", "Norm"], label="Blue Mode", value="Abs"),
610
+ gr.Checkbox(value=False, label="Invert Gradients"),
611
+ gr.Checkbox(value=False, label="Equalize Histogram")
612
+ ],
613
+ outputs=gr.Image(type="pil"),
614
+ title="Gradient Processing",
615
+ description="Applies gradient filters to an image to enhance edges and transitions, which can reveal inconsistencies due to manipulation.",
616
+ api_name="tool_gradient_processing"
617
+ )
618
+ with gr.Tab("MinMax Processing", visible=False):
619
+ gr.Interface(
620
+ fn=minmax_preprocess,
621
+ inputs=[
622
+ gr.Image(type="pil", label="Input Image"),
623
+ gr.Radio([0, 1, 2, 3, 4], label="Channel (0:Grayscale, 1:Blue, 2:Green, 3:Red, 4:RGB Norm)", value=4),
624
+ gr.Slider(0, 10, value=2, step=1, label="Radius")
625
+ ],
626
+ outputs=gr.Image(type="pil"),
627
+ title="MinMax Processing",
628
+ description="Analyzes local pixel value deviations to detect subtle changes in image data, often indicative of digital forgeries.",
629
+ api_name="tool_minmax_processing"
630
+ )
631
  # --- MCP-Ready Launch ---
632
  if __name__ == "__main__":
633
  # Initialize CommitScheduler