mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
Paper: 'Ultra-fast computation of fractal dimension for RGB images' (Pattern Analysis and Applications, 2025) Python (fractal_dimension.py): - DBC algorithm with numpy vectorization (29x faster than scalar) - fd_compress_hint: FD → voltage mode (STORE/COMPUTE/APPROX/MORPHIC) - 7/7 tests pass (Sierpinski, random, gradient, checkerboard, fBm, constant, RGB) - Q16_16 integer arithmetic internally FPGA (fractal_box_counter.v + fractal_fd_selector.v): - 5-state FSM: IDLE → COLLECT → FINALIZE → STORE_LOG → REGRESS → DONE - 8 power-of-two scales (2, 4, 8, ..., 256) - Linear regression via Q16_16 64-bit arithmetic - FD clamped to [1.0, 3.0] in Q16_16 - Selector: FD < 2.3 → STORE, < 2.6 → COMPUTE, < 2.9 → APPROX, >= 2.9 → MORPHIC - Integrated into research_stack_top.v FD drives adaptive compression: Low FD (smooth) → STORE mode (minimal compression) High FD (rough) → MORPHIC mode (aggressive compression)
65 lines
2 KiB
Verilog
65 lines
2 KiB
Verilog
`timescale 1ns / 1ps
|
|
|
|
// Fractal Dimension → Voltage Mode Selector
|
|
// Maps computed fractal dimension (Q16_16) to a 2-bit voltage mode for the
|
|
// voltage_mode_controller.
|
|
//
|
|
// FD < 2.3 → voltage_mode = 0 (STORE)
|
|
// FD < 2.6 → voltage_mode = 1 (COMPUTE)
|
|
// FD < 2.9 → voltage_mode = 2 (APPROX)
|
|
// FD >= 2.9 → voltage_mode = 3 (MORPHIC)
|
|
//
|
|
// Thresholds in Q16_16:
|
|
// 2.3 = 2 + 0.3 = 0x0002_4CCD (131072 + 19661 = 150733)
|
|
// 2.6 = 2 + 0.6 = 0x0002_999A (131072 + 39322 = 170394)
|
|
// 2.9 = 2 + 0.9 = 0x0002_E666 (131072 + 58982 = 190054)
|
|
|
|
module fractal_fd_selector (
|
|
input wire clk,
|
|
input wire rst_n,
|
|
input wire [31:0] fd_q16, // fractal dimension in Q16_16
|
|
input wire fd_valid, // fd_q16 is valid
|
|
output reg [1:0] voltage_mode, // 0=STORE, 1=COMPUTE, 2=APPROX, 3=MORPHIC
|
|
output reg mode_valid // mode output is valid
|
|
);
|
|
|
|
// Threshold constants in Q16_16
|
|
localparam [31:0] THRESH_2_3 = 32'h0002_4CCD; // 2.3
|
|
localparam [31:0] THRESH_2_6 = 32'h0002_999A; // 2.6
|
|
localparam [31:0] THRESH_2_9 = 32'h0002_E666; // 2.9
|
|
|
|
// Mode definitions (match voltage_mode_controller)
|
|
localparam MODE_STORE = 2'b00;
|
|
localparam MODE_COMPUTE = 2'b01;
|
|
localparam MODE_APPROX = 2'b10;
|
|
localparam MODE_MORPHIC = 2'b11;
|
|
|
|
// Combinational mode selection
|
|
reg [1:0] mode_next;
|
|
|
|
always @(*) begin
|
|
if (fd_q16 < THRESH_2_3)
|
|
mode_next = MODE_STORE;
|
|
else if (fd_q16 < THRESH_2_6)
|
|
mode_next = MODE_COMPUTE;
|
|
else if (fd_q16 < THRESH_2_9)
|
|
mode_next = MODE_APPROX;
|
|
else
|
|
mode_next = MODE_MORPHIC;
|
|
end
|
|
|
|
// Register output
|
|
always @(posedge clk or negedge rst_n) begin
|
|
if (!rst_n) begin
|
|
voltage_mode <= MODE_STORE;
|
|
mode_valid <= 1'b0;
|
|
end else begin
|
|
mode_valid <= 1'b0;
|
|
if (fd_valid) begin
|
|
voltage_mode <= mode_next;
|
|
mode_valid <= 1'b1;
|
|
end
|
|
end
|
|
end
|
|
|
|
endmodule
|