• SLIC algorithm with Atmospheric Light (A).

    From Dimitrios Tsitsos@21:1/5 to All on Mon Dec 7 02:39:31 2020
    Hello,
    I am in my last year of my Bachelor and before I graduate I have to complete my Thesis which is about Image dehazing.
    In the first step of my method I have to divide my haze image into superpixels using SLIC and then the superpixels with similar haze densities are merged into seperateregions.
    In contrast with what we already know about SLIC algorithm, a new feature is introduced, the Atmospheric light (A), to further imporve the clustering result.
    As a result, the image is converted in a 6-D vector : V = [CIELAB, x, y, A], instead of 5-D the we usually have in SLIC algorithm [CIELAB, x, y].
    My problem is that I dont know how to instert the A in my code.

    My code for SLIC lagorithm is this :

    win = 7;
    n1 = floor(win/2);
    lochange = -n1:n1;
    for i = 1:size(loc,1)
    H = G(loc(i,1)-n1:loc(i,1)+n1,loc(i,2)-n1:loc(i,2)+n1);
    [a1,b1] = min(H);
    [a2,b2] = min(a1);
    loc(i,1) = loc(i,1) + lochange(b1(b2));
    loc(i,2) = loc(i,2) + lochange(b2);
    c(i,:) = [a_lab(loc(i,1),loc(i,2),1) a_lab(loc(i,1),loc(i,2),2) a_lab(loc(i,1),loc(i,2),3) loc(i,1) loc(i,2)];
    end
    iter = 0;
    msg = 'Segmenting ...';
    x = 0;
    f = waitbar(x,msg);
    while iter < n

    for i2 = 1:size(a,1)
    for j2 = 1:size(a,2)
    dis = [];
    for k2 = 1:size(loc,1)
    if sqrt((i2-loc(k2,1))^2 + (j2 - loc(k2,2))^2) < 2*s
    d = sqrt((a_lab(i2,j2,1)-c(k2,1))^2 + (a_lab(i2,j2,2)-c(k2,2))^2 + (a_lab(i2,j2,3)-c(k2,3))^2) + m/s*sqrt((i2-c(k2,4))^2 + (j2-c(k2,5))^2);
    dis = [dis;d k2];
    end
    end
    if isempty(dis)
    else
    [mind,I] = min(dis(:,1));
    o(i2,j2) = dis(I,2);
    end
    end
    end

    for i3 = 1:size(loc,1)
    [row,col] = find(o==i3);
    if isempty(row) && isempty(col)
    else
    rowmean = round(mean(row));
    colmean = round(mean(col));
    c(i3,:)=[a_lab(rowmean,colmean,1) a_lab(rowmean,colmean,2) a_lab(rowmean,colmean,3) rowmean colmean];
    end
    end

    iter = iter +1;
    x = iter/(n);
    waitbar(x,f)

    AND the code for atmospheric light that I use is this :

    a = double(a);
    [height, width, ~] = size(a);
    patchSize = 15; %the patch size is set to be 15 x 15
    padSize = 7; % half the patch size to pad the image with for the array to
    %work (be centered at 1,1 as well as at height,1 and 1,width and height,width etc)
    JDark = zeros(height, width); % the dark channel
    imJ = padarray(a, [padSize padSize], Inf); % the new image
    % imagesc(imJ); colormap gray; axis off image
    for j = 1:height
    for i = 1:width
    % the patch has top left corner at (jj, ii)
    patch = imJ(j:(j+patchSize-1), i:(i+patchSize-1),:);
    % the dark channel for a patch is the minimum value for all
    % channels for that patch
    JDark(j,i) = min(patch(:));
    end
    end
    [height, width, ~] = size(a);
    imsize = width * height;
    numpx = floor(imsize/1000); % accomodate for small images
    JDarkVec = reshape(JDark,imsize,1); % a vector of pixels in JDark
    ImVec = reshape(a,imsize,3); % a vector of pixels in my image
    [JDarkVec, indices] = sort(JDarkVec); %sort
    indices = indices(imsize-numpx+1:end); % need the last few pixels because those are closest to 1
    atmSum = zeros(1,3);
    for ind = 1:numpx
    atmSum = atmSum + ImVec(indices(ind),:);
    end
    A = atmSum / numpx;

    The main problem is that with this code fot the A I can't find the sqrt that I want just like I did with the sqrt for CIELAB and X, Y.
    Please whoever knows something let me know.
    You will help me a lot!!!

    Thank you in advance!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)