feat: filtrage
This commit is contained in:
parent
6fc48a2f22
commit
6f2c0a2080
|
@ -76,7 +76,7 @@ hold on;
|
||||||
% Binarisation de l'image à partir des superpixels %
|
% Binarisation de l'image à partir des superpixels %
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
figure;
|
figure(4);
|
||||||
R = germes(:, 3);
|
R = germes(:, 3);
|
||||||
B = germes(:, 5);
|
B = germes(:, 5);
|
||||||
scatter(R, B);
|
scatter(R, B);
|
||||||
|
@ -104,7 +104,9 @@ figure(3);
|
||||||
% bw_img(:,1:5) = 0;
|
% bw_img(:,1:5) = 0;
|
||||||
% bw_img(:,end-30:end) = 0;
|
% bw_img(:,end-30:end) = 0;
|
||||||
|
|
||||||
|
subplot(2,2,1);
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
|
hold on
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,8 +120,7 @@ imshow(bw_img);
|
||||||
pixel_b = find(bw_img == 1);
|
pixel_b = find(bw_img == 1);
|
||||||
[r, c] = ind2sub(size(bw_img), pixel_b(1));
|
[r, c] = ind2sub(size(bw_img), pixel_b(1));
|
||||||
contour = bwtraceboundary(bw_img, [r c], 'W', 8);
|
contour = bwtraceboundary(bw_img, [r c], 'W', 8);
|
||||||
hold on
|
plot(contour(:,2), contour(:,1), 'g', 'LineWidth', 3);
|
||||||
plot(contour(:,2), contour(:,1),'g','LineWidth',5);
|
|
||||||
|
|
||||||
|
|
||||||
% r = delaunay(contour);
|
% r = delaunay(contour);
|
||||||
|
@ -129,8 +130,10 @@ plot(contour(:,2), contour(:,1),'g','LineWidth',5);
|
||||||
|
|
||||||
[vx, vy] = voronoi(contour(:,1), contour(:,2));
|
[vx, vy] = voronoi(contour(:,1), contour(:,2));
|
||||||
|
|
||||||
% plot(vy, vx, 'g');
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
|
|
||||||
|
% Selection des segments qui ont leurs extrémités dans l'image
|
||||||
ok = vx(1,:) > 0 & vx(1,:) < size(bw_img, 1) & ...
|
ok = vx(1,:) > 0 & vx(1,:) < size(bw_img, 1) & ...
|
||||||
vx(2,:) > 0 & vx(2,:) < size(bw_img, 1) & ...
|
vx(2,:) > 0 & vx(2,:) < size(bw_img, 1) & ...
|
||||||
vy(1,:) > 0 & vy(1,:) < size(bw_img, 2) & ...
|
vy(1,:) > 0 & vy(1,:) < size(bw_img, 2) & ...
|
||||||
|
@ -138,7 +141,12 @@ ok = vx(1,:) > 0 & vx(1,:) < size(bw_img, 1) & ...
|
||||||
vx = floor(vx(:,ok));
|
vx = floor(vx(:,ok));
|
||||||
vy = floor(vy(:,ok));
|
vy = floor(vy(:,ok));
|
||||||
|
|
||||||
% plot(vy, vx, 'b');
|
subplot(2,2,2);
|
||||||
|
imshow(bw_img);
|
||||||
|
hold on
|
||||||
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
|
% Selection des segments avec les extremités dans la forme
|
||||||
|
|
||||||
ind1 = sub2ind(size(bw_img), vx(1,:), vy(1,:));
|
ind1 = sub2ind(size(bw_img), vx(1,:), vy(1,:));
|
||||||
ok1 = bw_img(ind1) > 0;
|
ok1 = bw_img(ind1) > 0;
|
||||||
|
@ -150,8 +158,13 @@ ok = ok1 & ok2;
|
||||||
vx = vx(:,ok);
|
vx = vx(:,ok);
|
||||||
vy = vy(:,ok);
|
vy = vy(:,ok);
|
||||||
|
|
||||||
% plot(vy, vx, 'r');
|
subplot(2,2,3);
|
||||||
|
imshow(bw_img);
|
||||||
|
hold on
|
||||||
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
|
|
||||||
|
% Remise en forme de vx et vy
|
||||||
vx_ = vx';
|
vx_ = vx';
|
||||||
vx_ = [vx_(:,1) ; vx_(:,2)];
|
vx_ = [vx_(:,1) ; vx_(:,2)];
|
||||||
|
|
||||||
|
@ -160,27 +173,6 @@ vy_ = [vy_(:,1) ; vy_(:,2)];
|
||||||
|
|
||||||
V_ = [vx_ vy_];
|
V_ = [vx_ vy_];
|
||||||
|
|
||||||
% V_u = unique(V_, 'rows');
|
|
||||||
%
|
|
||||||
% adja = sparse(zeros(length(V_u)));
|
|
||||||
% for k = 1:length(V_) / 2
|
|
||||||
% i = find(V_(k, 1) == V_u(:, 1) & V_(k, 2) == V_u(:, 2));
|
|
||||||
% j = find(V_(2 * k, 1) == V_u(:, 1) & V_(2* k, 2) == V_u(:, 2));
|
|
||||||
% if i ~= j
|
|
||||||
% adja(i, j) = 1;
|
|
||||||
% adja(j, i) = 1;
|
|
||||||
% end
|
|
||||||
% plot([V_u(i,1) V_u(j,1)],[V_u(i,2) V_u(j,2)])
|
|
||||||
% end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
% adja = zeros(size(bw_img, 1), size(bw_img, 2));
|
|
||||||
% adja(vx_, vy_) = 1;
|
|
||||||
% adja = sparse(adja);
|
|
||||||
% adja = sparse(vx_, vy_, 1, size(bw_img, 1), size(bw_img, 2)) > 0;
|
|
||||||
% gplot(adja, V_u);
|
|
||||||
|
|
||||||
|
|
||||||
% Calcule des rayons
|
% Calcule des rayons
|
||||||
contour_ = contour';
|
contour_ = contour';
|
||||||
|
@ -189,8 +181,6 @@ R = abs(R);
|
||||||
R = min(R, [], 2);
|
R = min(R, [], 2);
|
||||||
R = R';
|
R = R';
|
||||||
|
|
||||||
% viscircles([V_(:,2) V_(:,1)], R);
|
|
||||||
|
|
||||||
% Filtrage naif
|
% Filtrage naif
|
||||||
% truc = find(R < 20);
|
% truc = find(R < 20);
|
||||||
% truc = mod(truc - 1, length(vx)) + 1;
|
% truc = mod(truc - 1, length(vx)) + 1;
|
||||||
|
@ -198,13 +188,21 @@ R = R';
|
||||||
% vx(:,truc) = [];
|
% vx(:,truc) = [];
|
||||||
% vy(:,truc) = [];
|
% vy(:,truc) = [];
|
||||||
|
|
||||||
%%
|
% Filtrage scalaire
|
||||||
|
R_scaled = 1.1 * R;
|
||||||
R_scaled = 1.34 * R;
|
|
||||||
dist = abs(complex(V_(:,1), V_(:,2)) - transpose(complex(V_(:,1), V_(:,2))));
|
dist = abs(complex(V_(:,1), V_(:,2)) - transpose(complex(V_(:,1), V_(:,2))));
|
||||||
|
|
||||||
|
R_vertical = ones(length(R_scaled),1) * R_scaled;
|
||||||
|
R_horizontal = R_scaled' * ones(1,length(R_scaled));
|
||||||
|
|
||||||
|
[~, c] = ind2sub(size(dist), find(dist + R_vertical < R_horizontal));
|
||||||
|
|
||||||
|
vx(:, mod(c - 1, length(vx)) + 1) = [];
|
||||||
|
vy(:, mod(c - 1, length(vy)) + 1) = [];
|
||||||
|
|
||||||
|
subplot(2,2,4);
|
||||||
|
imshow(bw_img);
|
||||||
|
hold on
|
||||||
plot(vy, vx, 'b');
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue