stegosphere.analysis package
Submodules
stegosphere.analysis.accuracy module
Accuracy metrics for comparing original and extracted binary payloads.
- stegosphere.analysis.accuracy.bit_error_rate(before, after)
Compute the bit error rate between two binary sequences.
- Parameters:
before (str | list | numpy.ndarray) – Original binary sequence.
after (str | list | numpy.ndarray) – Modified binary sequence.
- Returns:
Proportion of bits that differ.
- Return type:
float
- Raises:
ValueError – If inputs are not the same length.
- stegosphere.analysis.accuracy.hamming_distance(before, after)
Compute the Hamming distance between two binary strings or arrays.
- Parameters:
before (str | list | numpy.ndarray) – Original binary sequence.
after (str | list | numpy.ndarray) – Modified binary sequence.
- Returns:
Number of differing bits.
- Return type:
int
- Raises:
ValueError – If inputs are not the same length.
- stegosphere.analysis.accuracy.normalized_correlation(before, after)
Compute the normalized correlation between two sequences.
- Parameters:
before – Original numerical sequence.
after – Modified numerical sequence.
- Returns:
Normalized correlation coefficient. Returns 0 if denominator is zero.
- Return type:
float
- Raises:
ValueError – If inputs are not the same length.
stegosphere.analysis.capacity module
Measuring how much data can be stored within a cover.
In future versions, this should include heuristics using the max_capacity_estimator
- stegosphere.analysis.capacity.bits_per_value(array, max_capacity)
Compute bits per host‐value given total capacity.
- Parameters:
array (numpy.ndarray) – Host array.
max_capacity (int | float) – Total embedding capacity in bits.
- Returns:
Bits of payload per array element.
- Return type:
float
- stegosphere.analysis.capacity.bits_per_value_used(array, payload_size)
Compute actually used bits per host‐value.
- Parameters:
array (numpy.ndarray) – Host array.
payload_size (int | float) – Size of embedded payload in bits.
- Returns:
Payload bits per array element.
- Return type:
float
- stegosphere.analysis.capacity.max_capacity_estimator(*args)
- stegosphere.analysis.capacity.payload_ratio(payload_size, max_capacity)
Compute payload-to-capacity ratio.
- Parameters:
payload_size (int | float) – Size of embedded payload in bits.
max_capacity (int | float) – Maximum capacity in bits.
- Returns:
Ratio payload_size / max_capacity.
- Return type:
float
stegosphere.analysis.detectability module
A module to detect the likelihood of steganography
- stegosphere.analysis.detectability.random_detector(input_data)
Randomly decide presence of steganography (for testing).
- Parameters:
input_data – Any input; ignored in decision.
- Returns:
0 or 1, chosen uniformly at random.
- Return type:
int
- stegosphere.analysis.detectability.sp(X)
Estimate embedding rate (β̂) via Sample Pairs Analysis (Dumitrescu et al. 2002).
- Parameters:
X (array-like) – 2D array of integer pixel values.
- Returns:
Estimated embedding rate β̂ ∈ [0,1], or -1 if undetermined.
- Return type:
float
- Raises:
ValueError – If input is not a 2D array with at least 2 columns.
- stegosphere.analysis.detectability.uniformity_detector(array)
Detect likelihood of LSB steganography in an RGB image by uniformity of LSBs.
- Parameters:
array (array-like) – H×W×3 RGB image array of integers.
- Returns:
- Score ∈ [0,1], where higher means more uniform LSB distribution
(i.e. more likely stego).
- Return type:
float
- Raises:
ValueError – If input is not a 3D array with third dimension size 3.
stegosphere.analysis.efficiency module
Module for measuring elapsed and used memory of processes.
- class stegosphere.analysis.efficiency.EfficiencyProfiler
Bases:
object
- class stegosphere.analysis.efficiency.MemoryProfiler
Bases:
object
- class stegosphere.analysis.efficiency.Timer
Bases:
object
- stegosphere.analysis.efficiency.profile_function(func)
Decorator to time and measure memory of a function call. :returns: result, profiling_info (dict)
stegosphere.analysis.imperceptibility module
Measuring imperceptibility
- stegosphere.analysis.imperceptibility.bhattacharyya_divergence(array_1, array_2, epsilon=1e-10)
Compute Bhattacharyya distance between two distributions.
- Parameters:
array_1 (array-like) – Probability distributions or counts.
array_2 (array-like) – Probability distributions or counts.
epsilon (float) – Small constant to avoid log(0).
- Returns:
Bhattacharyya distance.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.chi_distance(array_1, array_2, epsilon=1e-10)
Compute chi-squared distance between two nonnegative arrays.
- Parameters:
array_1 (array-like) – Input histograms or nonnegative arrays.
array_2 (array-like) – Input histograms or nonnegative arrays.
epsilon (float) – Small constant to avoid division by zero.
- Returns:
Chi-squared distance.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.euclidean_distance(array_1, array_2)
Compute Euclidean (L2) distance between two arrays.
- Parameters:
array_1 (array-like) – Input arrays of equal shape.
array_2 (array-like) – Input arrays of equal shape.
- Returns:
Euclidean norm of differences.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.js_divergence(array_1, array_2, epsilon=1e-10)
Compute Jensen-Shannon divergence between two distributions.
- Parameters:
array_1 (array-like) – Probability distributions or counts.
array_2 (array-like) – Probability distributions or counts.
epsilon (float) – Small constant to avoid log(0).
- Returns:
JS divergence.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.kl_divergence(array_1, array_2, epsilon=1e-10)
Compute Kullback-Leibler divergence Dₖₗ(P‖Q).
- Parameters:
array_1 (array-like) – Probability distributions or counts.
array_2 (array-like) – Probability distributions or counts.
epsilon (float) – Small constant to avoid log(0).
- Returns:
KL divergence.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.manhattan_distance(array_1, array_2)
Compute Manhattan (L1) distance between two arrays.
- Parameters:
array_1 (array-like) – Input arrays of equal shape.
array_2 (array-like) – Input arrays of equal shape.
- Returns:
Sum of absolute differences.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.mse(array_1, array_2)
Compute Mean Squared Error (MSE) between two arrays.
- Parameters:
array_1 (array-like) – Input arrays of equal shape.
array_2 (array-like) – Input arrays of equal shape.
- Returns:
MSE value.
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.psnr(array_1, array_2, max_i=None)
Compute Peak Signal-to-Noise Ratio (PSNR) in decibels.
- Parameters:
array_1 (array-like) – Input arrays of equal shape.
array_2 (array-like) – Input arrays of equal shape.
max_i (number, optional) – Maximum possible pixel value. Defaults to dtype max of array_1.
- Returns:
PSNR value (inf if zero error).
- Return type:
float
- Raises:
ValueError – If shapes differ.
- stegosphere.analysis.imperceptibility.results(array_1, array_2, measures='all', epsilon=1e-10, psnr_max_i=None)
Compute multiple similarity/divergence/distance measures.
- Parameters:
array_1 (array-like) – Input arrays of equal shape.
array_2 (array-like) – Input arrays of equal shape.
measures (list or 'all') – Names of measures to compute.
epsilon (float, optional) – Small constant for stability.
psnr_max_i (number, optional) – Max value for PSNR.
- Returns:
{measure_name: value, …}
- Return type:
dict
- stegosphere.analysis.imperceptibility.ssim(array_1, array_2, **kwargs)
Compute Structural Similarity Index (SSIM) between two images.
- Parameters:
array_1 (ndarray) – Grayscale or multi-channel images.
array_2 (ndarray) – Grayscale or multi-channel images.
**kwargs – Passed to skimage.metrics.structural_similarity.
- Returns:
SSIM score (and image if full=True).
- Return type:
float or ndarray
- Raises:
ValueError – If shapes differ.
stegosphere.analysis.robustness module
A module for simulating attacks onto arrays.
- stegosphere.analysis.robustness.cropping_attack(image, crop_fraction=0.1)
Randomly crop and pad back to original size.
- Parameters:
image (ndarray) – Input image.
crop_fraction (float) – Fractional size to crop on each side.
- Returns:
Cropped and resized image.
- Return type:
ndarray
- stegosphere.analysis.robustness.gaussian_noise_attack(array, sigma=1.0)
Apply Gaussian smoothing as a low-pass filter.
- Parameters:
array (ndarray) – Input image or signal.
sigma (float) – Standard deviation for Gaussian kernel.
- Returns:
Smoothed result.
- Return type:
ndarray
- stegosphere.analysis.robustness.jpeg_compression_attack(image, quality=50)
Simulate JPEG compression artifacts.
- Parameters:
image (ndarray) – Input image in BGR or grayscale.
quality (int) – JPEG quality factor (0-100).
- Returns:
Compressed-then-decoded image.
- Return type:
ndarray
- stegosphere.analysis.robustness.random_bit_attack(array, ratio=0.01)
Randomly flip a given fraction of elements in the array by +1 or -1.
- Parameters:
array (array-like) – Input numeric array.
ratio (float) – Fraction of elements to perturb ∈ [0, 1].
- Returns:
Copy of the input with random ±1 perturbations applied.
- Return type:
np.ndarray
- Raises:
ValueError – If ratio is not between 0 and 1.
stegosphere.analysis.visualizer module
Module to visualize various measures. Currently mostly for images.
- stegosphere.analysis.visualizer.channel_correlation_plot(data)
Plot correlation between channels of a multichannel array.
- Parameters:
data (ndarray) – Multichannel array, last dim = channels.
- stegosphere.analysis.visualizer.difference_heatmap(orig, modified, title='Difference Heatmap', cmap='seismic', vmin=None, vmax=None)
Plot heatmap of differences between two arrays.
- Parameters:
orig (ndarray) – Arrays of the same shape.
modified (ndarray) – Arrays of the same shape.
title (str) – Plot title.
cmap (str) – Colormap.
vmin (float or None) – Value range for color scaling.
vmax (float or None) – Value range for color scaling.
- stegosphere.analysis.visualizer.histogram_comparison(original, modified, bins=256)
Compare histograms of two arrays.
- Parameters:
original (ndarray) – Input arrays.
modified (ndarray) – Input arrays.
bins (int) – Histogram bins.
- stegosphere.analysis.visualizer.plot_lsb_frequency(data)
Plot LSB frequency of an array (supports multichannel images, audio, etc.).
- Parameters:
data (ndarray) – Input array.
- stegosphere.analysis.visualizer.show_side_by_side(a1, a2, titles=('Original', 'Modified'))
Show two arrays (e.g., images, spectrograms) side by side.
- Parameters:
a1 (ndarray) – Arrays to show.
a2 (ndarray) – Arrays to show.
titles (tuple) – Subplot titles.
Module contents
The analysis package is a collection of various tools for steganalysis.