function result = fuzzy_contrast_toolbox(img, dt, gt, bt, vd, vg, vb)

    % Fuzzy Contrast Enhancement using MATLAB Fuzzy Logic Toolbox
    % This uses a Sugeno FIS to replicate the singleton output logic.
    
    % 1. Create a Sugeno Fuzzy Inference System
    % Sugeno is used because it naturally supports the constant (singleton) outputs.
    fis = sugfis('Name', 'ContrastEnhancement');
    
    % 2. Add Input Variable (Pixel Intensity: 0 to 255)
    fis = addInput(fis, [0 255], 'Name', 'Intensity');
    
    % 3. Add Input Membership Functions
    % We use 'trapmf' (trapezoidal) for the left/right shoulders and 'trimf' (triangular) for the center.  
    fis = addMF(fis, 'Intensity', 'trapmf', [0 0 dt gt], 'Name', 'Dark');
    fis = addMF(fis, 'Intensity', 'trimf',  [dt gt bt], 'Name', 'Gray');
    fis = addMF(fis, 'Intensity', 'trapmf', [gt bt 255 255], 'Name', 'Bright');
    
    % 4. Add Output Variable (Enhanced Intensity: 0 to 255)
    fis = addOutput(fis, [0 255], 'Name', 'Enhanced_Intensity');
    
    % 5. Add Output Membership Functions (Singletons / Constants)
    fis = addMF(fis, 'Enhanced_Intensity', 'constant', vd, 'Name', 'Darker');
    fis = addMF(fis, 'Enhanced_Intensity', 'constant', vg, 'Name', 'MidGray');
    fis = addMF(fis, 'Enhanced_Intensity', 'constant', vb, 'Name', 'Brighter');
    
    % 6. Add the Fuzzy Rules
    % This expresses the concepts of dark, gray, and bright modifying the output.
    ruleList = [
        "If Intensity is Dark then Enhanced_Intensity is Darker"
        "If Intensity is Gray then Enhanced_Intensity is MidGray"
        "If Intensity is Bright then Enhanced_Intensity is Brighter"
    ];
    fis = addRule(fis, ruleList);
    
    % 7. Apply the FIS to the image
    img_double = double(img);
    
    % Flatten the 2D image array into a 1D column vector 
    % Passing the whole array to evalfis is much faster than looping through pixels
    img_flat = img_double(:);
    
    % Evaluate the fuzzy system (handles fuzzification, implication, and defuzzification)
    out_flat = evalfis(fis, img_flat);
    
    % Reshape back to the original image dimensions and convert to uint8
    result = uint8(reshape(out_flat, size(img)));

end

