Metadata-Version: 2.4
Name: I2NeT
Version: 2.0.1
Summary: I2NeT (Images to Network Traffic), extract and reconstruct data from RGB-encoded PNG images into CSV format. Suitable for CNN-based anomaly detection.
Author-email: Omesh Fernando <omeshf@gmail.com>, Sajid Fadlelseed <sajidqurashi1@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/omeshF/I2NeT
Project-URL: Issues, https://github.com/omeshF/I2NeT/issues
Project-URL: Documentation, https://github.com/omeshF/I2NeT#readme
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Security
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 4 - Beta
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file


# 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](https://github.com/omeshF/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:

```bash
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

```bash
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:

```python
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:

```python
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:

```python
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:

```python
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](https://github.com/omeshF/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:

```python
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:

```bibtex
@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

- 🔗 [NeT2I GitHub Repository](https://github.com/omeshF/NeT2I)
- 🐞 [Report Issues](https://github.com/omeshF/I2NeT/issues)
