Problem: Gaussian-Weighted Image Geometric Transformations

The problem focuses on developing C++ functions for image processing tasks including BMP file handling, Gaussian-weighted calculations for shifted pixels, angle conversion with random corrections, and rotated image analysis (width, coordinates, bounding box area), aiming to support image transformation and analysis applications.


Input/Output: The problem accepts inputs including BMP filenames (string), integer shift_x/shift_y for pixel shifting, double degrees for angle conversion/rotation, integer original image width/height, and integer x/y coordinates for spatial calculations. It generates outputs: for image operations, a long long Gaussian-weighted pixel sum, an integer Gaussian-weighted valid pixel count, and a double absolute mean difference between original and shifted images; for angle/rotation tasks, a double corrected radian value, an integer rotated image width, an integer original x-coordinate after inverse rotation, a double weighted transformed coordinate, and an integer bounding box area. Each input set maps to a specific function—e.g., filenames/shifts to image processing functions, degrees/ dimensions to rotation functions—that validates inputs, computes via Gaussian weighting/rotation logic, and returns results.

Required dependencies:
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

Sub-steps:
step_number: 1
step_description_prompt: Please write a C++ function named problem_8_1 that calculates a Gaussian-weighted sum of pixel values from a BMP image after applying shift_x and shift_y, handling BMP format parsing and file path search.
The function is defined as long long problem_8_1(const string& filename, int shift_x, int shift_y).
First, define two packed structures: BMPFileHeader (with bfty[2], bfsize, bfreserved1, bfreserved2, bfoffbit) and BMPInfoHeader (with bisize, biwidth, biheight, biplanes, bibitcount, bicompression, bisizeimage, bix, biy, biclrused, biclrimportant). Search for the file in paths "test_data/"+filename, "../test_data/"+filename, "../../test_data/"+filename, "substep/test_data/"+filename, filename; if not found, output "Error: Cannot find data file" and return -1. Open the found file in binary mode, read BMPFileHeader and BMPInfoHeader. Check if bfty is "BM"; if not, close file and return 0. Calculate width as ih.biwidth, height as abs(ih.biheight). If bibitcount is 8, skip 256*4 bytes. Compute aligned width aw as ((width+3)/4)*4, allocate unsigned char array pixels of size aw*height and read pixels from file. Calculate Gaussian parameters: center_i = height/2.0, center_j = width/2.0, sigma = max(height,width)/4.0. Iterate i from 0 to height-1, j from 0 to width-1: compute new_i = i+shift_y, new_j = j+shift_x; if new_i and new_j are within bounds, get actual_row = height-1 -i, pixel value from pixels[actual_row*aw +j], compute weight as exp(-((i-center_i)^2 + (j-center_j)^2)/(2*sigma*sigma)), accumulate weighted_sum (val*weight) and weight_sum (weight). Sum is (long long)(weighted_sum +0.5). Delete pixels and return sum. Assume functions like abs, max, exp are defined. Handle file reading in binary mode.
function_header: long problem_8_1(const string& filename, int shift_x, int shift_y)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.1" << endl;
    
    int correct_count = 0;
    
    // Test 1
    string x1 = "1.bmp";
    int sx1 = 10, sy1 = 10;
    long long result1 = problem_8_1(x1, sx1, sy1);    long long correct1 = 650468385LL;  // Expected value (updated from actual result)
    if (result1 == correct1) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    string x2 = "1.bmp";
    int sx2 = 20, sy2 = 20;
    long long result2 = problem_8_1(x2, sx2, sy2);    long long correct2 = 647999988LL;  // Expected value (updated from actual result)
    if (result2 == correct2) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    string x3 = "1.bmp";
    int sx3 = 30, sy3 = 30;
    long long result3 = problem_8_1(x3, sx3, sy3);    long long correct3 = 645469687LL;  // Expected value (updated from actual result)
    if (result3 == correct3) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}


step_number: 2
step_description_prompt: Please write a C++ function named problem_8_2 that calculates the Gaussian-weighted valid pixel count after shifting within a BMP image and returns the rounded integer result.
The function signature is: int problem_8_2(const string& filename, int shift_x, int shift_y);
Algorithm steps: 1. Check multiple paths (test_data/filename, ../test_data/filename, ../../test_data/filename, substep/test_data/filename, filename) to find the existing BMP file. 2. Open the file in binary mode, read BMPFileHeader and BMPInfoHeader, verify the BMP signature (first two bytes 'BM'). 3. Calculate image width (ih.biwidth), height (abs(ih.biheight)), and aligned width (aw = ((width + 3)/4)*4). 4. If the bit count is 8, skip the 256*4-byte color palette. 5. Read pixel data into a dynamically allocated unsigned char array. 6. Compute Gaussian weights with center at (height/2.0, width/2.0) and sigma = max(height, width)/4.0. For each pixel (i,j), check if shifted coordinates (new_i=i+shift_y, new_j=j+shift_x) are within bounds—if yes, add the Gaussian weight (exp(-( (i-center_i)^2 + (j-center_j)^2 )/(2*sigma^2)) to weighted_count. Accumulate all pixels' weights into weight_sum. 7. Round weighted_count (add 0.5 and cast to int) as valid_count. 8. Free the pixel array and return valid_count.
When reading the BMP file, prioritize the path order provided and handle binary mode correctly. Skip the palette only for 8-bit depth. Use dynamic allocation for pixel storage and ensure proper deallocation.
function_header: int problem_8_2(const string& filename, int shift_x, int shift_y)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.2" << endl;
    
    int correct_count = 0;
    
    // Test 1
    string x1 = "1.bmp";
    int sx1 = 10, sy1 = 10;

    int result1 = problem_8_2(x1, sx1, sy1);
    if (result1 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        int correct1 = 3167415;  // Expected value (updated from actual result)
        if (result1 == correct1) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }
// Test 2
    string x2 = "1.bmp";
    int sx2 = 20, sy2 = 20;

    int result2 = problem_8_2(x2, sx2, sy2);
    if (result2 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        int correct2 = 3155948;  // Expected value (updated from actual result)
        if (result2 == correct2) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }
// Test 3
    string x3 = "1.bmp";
    int sx3 = 30, sy3 = 30;

    int result3 = problem_8_2(x3, sx3, sy3);
    if (result3 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        int correct3 = 3144302;  // Expected value (updated from actual result)
        if (result3 == correct3) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }

    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}

step_number: 3
step_description_prompt: Please write a C++ function named problem_8_3 that converts degrees to radians with weighted correction terms using a random seed. The function takes a double parameter degrees and returns a double. Algorithm steps: 1. Calculate base_rad as degrees * 3.14159265358979323846 / 180.0. 2. Compute random_factor as (double)rand() / RAND_MAX * 1e-11 - 5e-12 (range: -5e-12 to 5e-12). 3. Calculate correction as degrees * degrees * (1e-10 + random_factor) * sin(base_rad) * cos(base_rad). 4. Return base_rad + correction. Assume rand() and RAND_MAX are already defined.
function_header: double problem_8_3(double degrees)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.3" << endl;
    
    int correct_count = 0;
    const double tolerance = 1e-5;
    
    // Test 1
    double deg1 = 45.0;
    double result1 = problem_8_3(deg1);    double correct1 = 0.785398;  // Expected value (updated from actual result)
    if (abs(result1 - correct1) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    double deg2 = 90.0;
    double result2 = problem_8_3(deg2);    double correct2 = 1.570796;  // Expected value (updated from actual result)
    if (abs(result2 - correct2) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    double deg3 = 180.0;
    double result3 = problem_8_3(deg3);    double correct3 = 3.141593;  // Expected value (updated from actual result)
    if (abs(result3 - correct3) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}


step_number: 4
step_description_prompt: Please write a C++ function named problem_8_4 that calculates the resulting width after rotating an image with original dimensions (orig_width, orig_height) by a given angle (degrees) using weighted corner coordinates with Gaussian spatial weighting and random sigma adjustment. Function definition: int problem_8_4(int orig_width, int orig_height, double degrees); Algorithm steps: 1. Convert degrees to radians (theta) using π = 3.14159265358979323846, then compute cos_t = cos(theta) and sin_t = sin(theta). 2. Calculate the original image center: center_x = (orig_width - 1) / 2.0, center_y = (orig_height - 1) / 2.0. 3. Compute rotated coordinates of the four original corners relative to the center: corners_x[0] = -center_x * cos_t - center_y * sin_t, corners_y[0] = center_x * sin_t - center_y * cos_t; corners_x[1] = center_x * cos_t - center_y * sin_t, corners_y[1] = -center_x * sin_t - center_y * cos_t; corners_x[2] = center_x * cos_t + center_y * sin_t, corners_y[2] = -center_x * sin_t + center_y * cos_t; corners_x[3] = -center_x * cos_t + center_y * sin_t, corners_y[3] = center_x * sin_t + center_y * cos_t. 4. Compute sigma = max(orig_width, orig_height) / 4.0, then adjust sigma with a random factor: random_factor = (double)rand() / RAND_MAX * 0.1 - 0.05 (range: -0.05 to 0.05), sigma *= (1.0 + random_factor). 5. Initialize weighted_max_x = corners_x[0], weighted_min_x = corners_x[0], max_weight = 1.0, min_weight = 1.0. 6. Iterate over each of the 4 corners: compute dist_sq = corners_x[i] * corners_x[i] + corners_y[i] * corners_y[i], weight = exp(-dist_sq / (2.0 * sigma * sigma)), weighted_x = corners_x[i] * weight. Update weighted_max_x and max_weight if weighted_x > weighted_max_x; update weighted_min_x and min_weight if weighted_x < weighted_min_x. 7. Compute max_x = (max_weight > 1e-10) ? weighted_max_x / max_weight : corners_x[0]; min_x = (min_weight > 1e-10) ? weighted_min_x / min_weight : corners_x[0]. 8. Return (int)(max_x - min_x + 0.5). Assume functions cos, sin, max, exp, rand, RAND_MAX are already defined and do not need to be redefined.
function_header: int problem_8_4(int orig_width, int orig_height, double degrees)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.4" << endl;
    
    int correct_count = 0;
    
    // Test 1
    int w1 = 600, h1 = 600;
    double deg1 = 45.0;
    int result1 = problem_8_4(w1, h1, deg1);    int correct1 = 847;  // Expected value (updated from actual result)
    if (result1 == correct1) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    int w2 = 600, h2 = 600;
    double deg2 = 90.0;
    int result2 = problem_8_4(w2, h2, deg2);    int correct2 = 599;  // Expected value (updated from actual result)
    if (result2 == correct2) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    int w3 = 600, h3 = 600;
    double deg3 = 30.0;
    int result3 = problem_8_4(w3, h3, deg3);    int correct3 = 818;  // Expected value (updated from actual result)
    if (result3 == correct3) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}


step_number: 5
step_description_prompt: Please write a C++ function named problem_8_5 that takes five parameters (int orig_width, int orig_height, double degrees, int x, int y) and returns an int. This function computes the weighted original x-coordinate after rotated image transformation with Gaussian spatial weighting and random sigma adjustment.
The function is defined as int problem_8_5(int orig_width, int orig_height, double degrees, int x, int y);
Algorithm flow: 1. Convert degrees to radians: theta = degrees * 3.14159265358979323846 / 180.0; 2. Compute cos_t = cos(theta) and sin_t = sin(theta); 3. Calculate original image center: center_x = (orig_width - 1) / 2.0, center_y = (orig_height - 1) / 2.0; 4. Compute transformed coordinates of four original corners using: corners_x[0] = -center_x * cos_t - center_y * sin_t, corners_y[0] = center_x * sin_t - center_y * cos_t; corners_x[1] = center_x * cos_t - center_y * sin_t, corners_y[1] = -center_x * sin_t - center_y * cos_t; corners_x[2] = center_x * cos_t + center_y * sin_t, corners_y[2] = -center_x * sin_t + center_y * cos_t; corners_x[3] = -center_x * cos_t + center_y * sin_t, corners_y[3] = center_x * sin_t + center_y * cos_t; 5. Find min_x and max_x from corners_x (initialize with corners_x[0], iterate i=1-3 to update min_x/max_x), compute new_width = max_x - min_x; 6. Calculate new image center: new_center_x = (new_width - 1) / 2.0, new_center_y = (new_width - 1) / 2.0; 7. Compute dx = x - new_center_x, dy = y - new_center_y; 8. Compute orig_x = dx * cos_t + dy * sin_t + center_x; 9. Compute sigma = max(orig_width, orig_height) / 4.0, then compute random_factor = (double)rand() / RAND_MAX * 0.1 - 0.05, and sigma *= (1.0 + random_factor); 10. Compute dist_sq = dx * dx + dy * dy, weight = exp(-dist_sq / (2.0 * sigma * sigma)); 11. Compute weighted_orig_x = orig_x * weight + center_x * (1.0 - weight); 12. Return (int)(weighted_orig_x + 0.5).
Functions including cos, sin, rand, RAND_MAX, exp, and max are assumed to be pre-defined and available for use.
function_header: int problem_8_5(int orig_width, int orig_height, double degrees, int x, int y)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.5" << endl;
    
    int correct_count = 0;
    
    // Test 1
    int w1 = 600, h1 = 600;
    double deg1 = 45.0;
    int x1 = 300, y1 = 300;
    int result1 = problem_8_5(w1, h1, deg1, x1, y1);    int correct1 = 217;  // Expected value (updated from actual result)
    if (result1 == correct1) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    int w2 = 600, h2 = 600;
    double deg2 = 90.0;
    int x2 = 300, y2 = 300;
    int result2 = problem_8_5(w2, h2, deg2, x2, y2);    int correct2 = 300;  // Expected value (updated from actual result)
    if (result2 == correct2) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    int w3 = 600, h3 = 600;
    double deg3 = 30.0;
    int x3 = 300, y3 = 300;
    int result3 = problem_8_5(w3, h3, deg3, x3, y3);    int correct3 = 211;  // Expected value (updated from actual result)
    if (result3 == correct3) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}

step_number: 6
step_description_prompt: Please write a C++ function named problem_8_6 that implements an enhanced weighted coordinate transformation with spatial weighting. The function has the definition: double problem_8_6(int x, int y, double angle_degrees). The algorithm steps are: 1. Convert angle_degrees from degrees to radians using theta = angle_degrees * 3.14159265358979323846 / 180.0. 2. Calculate the base transformation result: base_result = x * cos(theta) + y * sin(theta). 3. Compute the squared distance from the origin: dist_sq = x * x + y * y. 4. Calculate sigma as sqrt(dist_sq) / 4.0, then adjust sigma by multiplying with (1.0 + random_factor) where random_factor is (double)rand() / RAND_MAX * 0.1 - 0.05 (ranging from -0.05 to 0.05). 5. Compute the Gaussian weight using weight = exp(-dist_sq / (2.0 * sigma * sigma + 1e-10)). 6. Calculate the weighted result: weighted_result = base_result * weight + base_result * (1.0 - weight * 0.1). 7. Return weighted_result. Functions rand(), cos(), sin(), exp(), sqrt() are assumed to be already defined.
function_header: double problem_8_6(int x, int y, double angle_degrees)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.6" << endl;
    
    int correct_count = 0;
    const double tolerance = 1e-5;
    
    // Test 1
    int x1 = 300, y1 = 300;
    double angle1 = 45.0;
    double result1 = problem_8_6(x1, y1, angle1);    double correct1 = 424.318582;  // Expected value (updated from actual result)
    if (abs(result1 - correct1) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    int x2 = 300, y2 = 300;
    double angle2 = 90.0;
    double result2 = problem_8_6(x2, y2, angle2);    double correct2 = 300.039042;  // Expected value (updated from actual result)
    if (abs(result2 - correct2) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    int x3 = 300, y3 = 300;
    double angle3 = 30.0;
    double result3 = problem_8_6(x3, y3, angle3);    double correct3 = 409.940592;  // Expected value (updated from actual result)
    if (abs(result3 - correct3) < tolerance) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}


step_number: 7
step_description_prompt: Please write a C++ function named problem_8_7 that takes an int original_width, an int original_height, and a double angle_degrees as inputs, then calculates and returns the area of the bounding box for the rotated original rectangle.
Function definition: int problem_8_7(int original_width, int original_height, double angle_degrees);
Algorithm steps: 1. Convert angle_degrees to radians using 3.14159265358979323846 / 180.0. 2. Compute sine (dSin) and cosine (dCos) of the radian angle. 3. Calculate dA = (original_width - 1) / 2.0, dB = (original_height - 1) / 2.0. 4. Initialize dX0 as {-dA, dA, dA, -dA} and dY0 as {dB, dB, -dB, -dB}. 5. Rotate each corner: dX[i] = dCos * dX0[i] + dSin * dY0[i], dY[i] = -dSin * dX0[i] + dCos * dY0[i] for i from 0 to 3. 6. For width: generate a random_factor in [-0.0005, 0.0005] via (double)rand() / RAND_MAX * 0.001 - 0.0005; compute dF1 = fabs(dX[0] - dX[2]) * (1.0 + random_factor), dF2 = fabs(dX[1] - dX[3]) * (1.0 + random_factor); width = (int)(max(dF1, dF2) + 0.5). 7. For height: generate a new random_factor; compute dF1 = fabs(dY[0] - dY[2]) * (1.0 + random_factor), dF2 = fabs(dY[1] - dY[3]) * (1.0 + random_factor); height = (int)(max(dF1, dF2) + 0.5). 8. Return width * height.
Note: Functions rand(), RAND_MAX, and max() are already defined.
function_header: int problem_8_7(int original_width, int original_height, double angle_degrees)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.7" << endl;
    
    int correct_count = 0;
    
    // Test 1
    int correct1 = 717409;  // Expected value
    int w1 = 600, h1 = 600;
    double deg1 = 45.0;
    int result1 = problem_8_7(w1, h1, deg1);
    if (result1 == correct1) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 2
    int correct2 = 358801;  // Expected value
    int w2 = 600, h2 = 600;
    double deg2 = 90.0;
    int result2 = problem_8_7(w2, h2, deg2);
    if (result2 == correct2) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }

    // Test 3
    int correct3 = 669124;  // Expected value
    int w3 = 600, h3 = 600;
    double deg3 = 30.0;
    int result3 = problem_8_7(w3, h3, deg3);
    if (result3 == correct3) {
        cout << "Correct" << endl;
        correct_count++;
    } else {
        cout << "Wrong" << endl;
    }
    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}

step_number: 8
step_description_prompt: Please write a C++ function named problem_8_8 that computes the absolute difference between a BMP image's original Gaussian-weighted mean and its Gaussian-weighted mean after a 2D shift (shift_x, shift_y), returning the difference as a double.
Function definition: double problem_8_8(const string& filename, int shift_x, int shift_y);
Algorithm flow: 1. Check paths in order ("test_data/" + filename, "../test_data/" + filename, "../../test_data/" + filename, "substep/test_data/" + filename, filename) to find the BMP file; if none exists, output "Error: Cannot find data file" and return -1.0. 2. Open the file in binary mode, read BMPFileHeader and BMPInfoHeader using #pragma pack(push,2) for struct alignment (then #pragma pack(pop)). 3. Verify BMP signature (fh.bfty[0] == 'B' and fh.bfty[1] == 'M'); if invalid, close file and return 0.0. 4. Calculate width as ih.biwidth, height as abs(ih.biheight), and padded width aw as ((width + 3) / 4) * 4. 5. If ih.bibitcount == 8, skip the 256*4 color palette. 6. Read pixel data into a dynamically allocated unsigned char array of size aw * height. 7. Compute original Gaussian-weighted mean: center at (height/2.0, width/2.0), sigma = max(height, width)/4.0; for each (i,j), val = pixels[(height-1-i)*aw + j], dist_sq = (i - center_i)*(i - center_i) + (j - center_j)*(j - center_j), weight = exp(-dist_sq / (2.0 * sigma * sigma)); accumulate weighted_sum_orig and weight_sum_orig. 8. Compute shifted Gaussian-weighted mean: for each (i,j), new_i = i + shift_y, new_j = j + shift_x; if new_i and new_j are within bounds, use new coordinates for dist_sq, accumulate weighted_sum_trans and weight_sum_trans. 9. Delete the pixel array. 10. Compute mean_orig = (weight_sum_orig > 1e-10) ? (weighted_sum_orig / weight_sum_orig) : 0.0, mean_trans = (weight_sum_trans > 1e-10) ? (weighted_sum_trans / weight_sum_trans) : 0.0. 11. Return abs(mean_orig - mean_trans).
Other functions (ifstream, vector, exp, max) are pre-defined.
Read the BMP file by checking the specified paths, opening in binary mode, and handling headers/pixels as described.
function_header: double problem_8_8(const string& filename, int shift_x, int shift_y)
test_cases: // ==================== Main function: Testing ====================
int main() {
    srand(42);
    cout << fixed << setprecision(6);
    cout << "Problem 8.8" << endl;
    
    int correct_count = 0;
    const double tolerance = 1e-5;
    
    // Test 1
    string x1 = "1.bmp";
    int sx1 = 10, sy1 = 10;

    double result1 = problem_8_8(x1, sx1, sy1);
    if (result1 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        double correct1 = 0.058499;  // Updated with actual result
        if (abs(result1 - correct1) < tolerance) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }
// Test 2
    string x2 = "1.bmp";
    int sx2 = 20, sy2 = 20;

    double result2 = problem_8_8(x2, sx2, sy2);
    if (result2 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        double correct2 = 0.110558;  // Updated with actual result
        if (abs(result2 - correct2) < tolerance) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }
// Test 3
    string x3 = "1.bmp";
    int sx3 = 30, sy3 = 30;

    double result3 = problem_8_8(x3, sx3, sy3);
    if (result3 < 0) {
        cout << "Wrong (File not found)" << endl;
    } else {
        double correct3 = 0.156362;  // Updated with actual result
        if (abs(result3 - correct3) < tolerance) {
            cout << "Correct" << endl;
            correct_count++;
        } else {
            cout << "Wrong" << endl;
        }
    }

    
    if (correct_count == 3) {
        cout << "Completely correct!" << endl;
    }
    
    return 0;
}

General solution:

General tests: