Skip to content

HCCVIcmr2019

stegobox.codec.hccv_icmr2019.HCCVIcmr2019

Bases: BaseCodec

This steganography method is named: HCCV.

  • Created by: Jiayao Yang
  • Created time: 2022/11/17

This is a PyTorch implementation of image steganography via deep learning, which is released in paper - High-Capacity Convolutional Video Steganography with Temporal Residual Modeling: Atenrev/Deep-Image-Steganography-Reimplementation.

Source code in stegobox/codec/hccv_icmr2019/hccv.py
class HCCVIcmr2019(BaseCodec):
    """
    This steganography method is named: HCCV.

    * Created by: Jiayao Yang
    * Created time: 2022/11/17

    This is a PyTorch implementation of image steganography via deep learning, which is
    released in paper - High-Capacity Convolutional Video Steganography with Temporal
    Residual Modeling:
    [Atenrev/Deep-Image-Steganography-Reimplementation](https://github.com/Atenrev/Deep-Image-Steganography-Reimplementation).
    """

    def __init__(
        self,
        image_size: int = 512,
        weights: str = "ckpt/hccv_icmr2019/autosteganographer.pth",
    ) -> None:
        super().__init__()
        self.image_size = image_size
        self.weights = weights

    def _transform(self, image: Image.Image) -> torch.Tensor:
        transform = transforms.Compose(
            [
                transforms.Resize([self.image_size, self.image_size]),
                transforms.ToTensor(),
            ]
        )
        return transform(image)  # type: ignore

    def encode(self, carrier: Image.Image, payload: Image.Image) -> torch.Tensor:
        """Encode image with format jpeg into image with format jpeg.

        Args:
            carrier: cover image
            payload: Payload secret image

        Returns:
            Encoded steganographic image with format torch.tensor
        """

        model = AutoSteganographer()
        model.load_state_dict(torch.load(self.weights))

        # read the carrier
        image_original = carrier.convert("RGB")
        image_original = self._transform(image_original)[None, :]

        # read the payload
        image_to_hide = payload.convert("RGB")
        image_to_hide = self._transform(image_to_hide)[None, :]

        # encode the payload
        result = model.merge(image_original, image_to_hide)

        return result

    def decode(self, carrier: Image.Image) -> torch.Tensor:
        """Decode secret image from encoded steganographic image.

        Args:
            carrier: Encoded carrier image.

        Returns:
            The decoded image if decode is successful.
        """

        model = AutoSteganographer()
        model.load_state_dict(torch.load(self.weights))

        # read the carrier
        image_original = carrier.convert("RGB")
        image_original = self._transform(image_original)[None, :]

        # reveal the payload
        result = model.revealer(image_original)
        # save_image(result, os.path.join(self.temp_out, self.output_recover))

        return result

encode(carrier, payload)

Encode image with format jpeg into image with format jpeg.

Parameters:

Name Type Description Default
carrier Image

cover image

required
payload Image

Payload secret image

required

Returns:

Type Description
Tensor

Encoded steganographic image with format torch.tensor

Source code in stegobox/codec/hccv_icmr2019/hccv.py
def encode(self, carrier: Image.Image, payload: Image.Image) -> torch.Tensor:
    """Encode image with format jpeg into image with format jpeg.

    Args:
        carrier: cover image
        payload: Payload secret image

    Returns:
        Encoded steganographic image with format torch.tensor
    """

    model = AutoSteganographer()
    model.load_state_dict(torch.load(self.weights))

    # read the carrier
    image_original = carrier.convert("RGB")
    image_original = self._transform(image_original)[None, :]

    # read the payload
    image_to_hide = payload.convert("RGB")
    image_to_hide = self._transform(image_to_hide)[None, :]

    # encode the payload
    result = model.merge(image_original, image_to_hide)

    return result

decode(carrier)

Decode secret image from encoded steganographic image.

Parameters:

Name Type Description Default
carrier Image

Encoded carrier image.

required

Returns:

Type Description
Tensor

The decoded image if decode is successful.

Source code in stegobox/codec/hccv_icmr2019/hccv.py
def decode(self, carrier: Image.Image) -> torch.Tensor:
    """Decode secret image from encoded steganographic image.

    Args:
        carrier: Encoded carrier image.

    Returns:
        The decoded image if decode is successful.
    """

    model = AutoSteganographer()
    model.load_state_dict(torch.load(self.weights))

    # read the carrier
    image_original = carrier.convert("RGB")
    image_original = self._transform(image_original)[None, :]

    # reveal the payload
    result = model.revealer(image_original)
    # save_image(result, os.path.join(self.temp_out, self.output_recover))

    return result