Skip to main content

I2NeT (Images to Network Traffic), extract and reconstruct data from RGB-encoded PNG images into CSV format. Suitable for CNN-based anomaly detection.

Project description

I2NeT - Image to Network

I2NeT (Image to Network) is the reverse companion to NeT2I. It decodes RGB images created from network traffic data back into structured tabular form.

This tool is purpose-built to only decode .png images generated using NeT2I. It restores data types including IPs, MACs, integers, floats, and hashed strings, ensuring accurate reconstruction for further analysis.

🧩 I2NeT decodes only the format output by NeT2I. Images from other tools will not decode correctly.


🎯 Key Features

  • 🔁 Reverses RGB images generated by NeT2I into CSV-format network traffic data
  • 🧠 Supports automatic or guided decoding using data_types.json
  • 💡 Recognizes and reconstructs:
    • IP addresses
    • MAC addresses
    • Integers and floats (via IEEE 754)
    • Strings (via consistent hash representations)
  • 🖼️ Processes one .png image per data row

🛠️ Requirements

  • Python 3.9+
  • Pillow
  • NumPy

Install dependencies:

pip install pillow numpy

🚀 Getting Started

1. Prepare Your Images

Ensure that .png images are located in a data/ directory:

data/
├── 0.png
├── 1.png
├── ...

You may optionally include a data_types.json file for better reconstruction accuracy (especially for IP and MAC decoding).

2. Run the Decoder

python i2net.py

This will:

  • Load all PNG images in data/
  • Decode the pixel data back to floats
  • Reconstruct column types (with or without a schema)
  • Write the output to:
from_image.csv

🧬 How It Works

Encoded Type Decoding Logic
🧾 Float / Int Extracted from 2 RGB pixels → 6 bytes → IEEE 754
🌐 IP Address 4 octets → 4 floats → 2 pixels each
🕸️ MAC Address 2 hex chunks → floats → decoded as 12-char hex
🔐 String Hash (SHA-1→int) → float → approximate reconstruction (optional)

Each 6-byte chunk (2 pixels) is read and unpacked into a float using struct.unpack(). Typed decoding relies on type hints stored in data_types.json.


📁 Output Structure

File Description
from_image.csv Final decoded output
data_types.json (optional) Guides the decoder in assigning column types
data/*.png Input image files, one per data row (from NeT2I)

📦 Usage Examples

Basic Usage:

import I2NeT.decoder as decoder

# Simple decoding
results = decoder.load_data('data', 'decoded_images.csv')
print(f"Decoded {results['successful_rows']} rows with {results['success_rate']:.1f}% success rate")

Advanced Usage with Custom Parameters:

import I2NeT.decoder as decoder

# Custom configuration
results = decoder.load_data(
    data_directory='my_images',
    output_csv='my_decoded_data.csv',
    types_file='my_types.json',
    verbose=True
)

# Access detailed results
print(f"Processed {results['processed_images']}/{results['total_images']} images")
print(f"Successfully decoded {results['successful_rows']} rows")
print(f"Type information: {results['type_info']['original_types']}")

Object-Oriented Usage:

from I2NeT.decoder import I2NeT_Decoder

# Create decoder instance
decoder = I2NeT_Decoder(types_file='data_types.json')

# Decode multiple datasets
results1 = decoder.load_data('dataset1_images', 'output1.csv')
results2 = decoder.load_data('dataset2_images', 'output2.csv')

# Decode single image
single_result = decoder.decode_single_image('data/0.png')
print(f"Single image decoded to: {single_result}")

Single Image Decoding:

import I2NeT.decoder as decoder

# Decode just one image
values = decoder.decode_single_image('data/0.png')
print(f"Decoded values: {values}")

🔄 Compatible Only With NeT2I

I2NeT only works on RGB images generated by NeT2I. These images are structured using a two-pixel-per-float strategy that preserves byte precision. Any other source of images will result in invalid outputs.


🧪 Example Use Case

This decoding tool is ideal for:

  • Verifying the integrity of image-encoded datasets before CNN training
  • Debugging failed predictions by mapping CNN outputs back to raw features
  • Regenerating partial data from anomaly-detected image samples

⚙️ Config Options

You can modify these variables at the top of the script:

INPUT_DIR = "data"
OUTPUT_FILE = "from_image.csv"
TYPES_FILE = "data_types.json"

📖 Citation

If you use I2NeT or NeT2I in your work, please cite:

@inproceedings{fernando2023new,
  title={New algorithms for the detection of malicious traffic in 5g-mec},
  author={Fernando, Omesh A and Xiao, Hannan and Spring, Joseph},
  booktitle={2023 IEEE Wireless Communications and Networking Conference (WCNC)},
  pages={1--6},
  year={2023},
  organization={IEEE}
}

👤 Authors

  • Omesh Fernando
  • Sajid Fadlelseed

📜 License

This project is licensed under the MIT License.


🌐 Project Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i2net-2.0.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

i2net-2.0.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file i2net-2.0.1.tar.gz.

File metadata

  • Download URL: i2net-2.0.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for i2net-2.0.1.tar.gz
Algorithm Hash digest
SHA256 cb75ffaa03d4715aea9a4835bca2c918478d6572afb6dae405299c5de2015cd1
MD5 4039f6722d4cc2e066fcd94fdd1debbb
BLAKE2b-256 a1f5e4e45d972a693fefa8bdeda7a13066de81905cbb22e0338561a619585072

See more details on using hashes here.

File details

Details for the file i2net-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: i2net-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for i2net-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5332ad90c6ddcdfd7b4cc8bc84dfa4b7d3a7e85c021696c65641e23e40105a4f
MD5 c3a72c33e5f3ae31822367109403db75
BLAKE2b-256 491cf6336863e417724cd23150d7187365f95234d188976979be0b5f15b41a4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page