Last active
April 19, 2019 16:47
-
-
Save avbelyaev/58878ce95ba3837c288db03c8603647c to your computer and use it in GitHub Desktop.
magaz 22feb. fourier, convolution, skeletonize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% with all respect to Maria | |
SobelD = [1 2 1; 0 0 0; -1 -2 -1]; %ядро или оператор собеля для свертки down | |
SobelR = [-1 0 1; -2 0 2; -1 0 1]; %ядро или оператор собеля для свертки right | |
P = imread('BioID_0508.pgm'); %исходное изображение | |
C1 = conv2(SobelD, P); %conv2 оператор свертки | |
C2 = conv2(SobelR, P); | |
C = sqrt(C1.^2 + C2.^2); %формулка из Вики | |
imwrite(P, gray(256), 'init.png', 'png'); %исходное изображение в другом формате | |
imwrite(C, gray(256), 'test1.png', 'png'); %изображение после применения оператора собеля | |
%снижаем "шумы" в изображении после | |
for j=1:386 | |
for i=1:288 | |
if C(i,j)>= 100 %это значение можно менять как угодно | |
C(i,j) = 255; %это тоже | |
else | |
C(i,j) = 0; | |
end | |
end | |
end | |
imwrite(C, gray(256), 'test2.png', 'png'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% здесь происходит что-то умное, но по факту чуть-чуть выделяются контуры на изображении :) | |
% конченая разность изображения | |
P = imread('jpeg/ImgBD/BioID/BioID_0168.pgm'); | |
for i = 1:285 | |
for j = 2:383 | |
x = P(i,j); | |
P(i,j) = x - P(i, j + 1); | |
end | |
end | |
for i = 1:285 | |
for j = 2:383 | |
x = P(i,j); | |
P(i,j) = x - P(i + 1, j); | |
end | |
end | |
imwrite(P, gray(256), 'test2.png', 'png'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% преобразование фурье | |
% (C) Maria | |
% main function should have same name as file and should be on top | |
function y = main() | |
x = (1:100); | |
y = (1:100); | |
min = -pi; | |
max = pi; | |
dx = (max - min) / 100; | |
for i = 1:100 | |
x(i) = -pi + i*dx; | |
y(i) = fourier(x(i)); | |
end | |
plot(x,y); | |
end | |
function sum = fourier(x) | |
sum = 2*pi; | |
for n = 1:1000 | |
an = 4 * sin(pi * n/2) / (pi*n); | |
bn = 0; | |
sum = sum + an * cos(n*x / 2) - bn*sin(n*x/2); | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear all; | |
img = imread('jpeg/ImgBD/BioID/BioID_0003.pgm'); | |
[img_h, img_w, dim] = size(img); | |
sobelm_x = [ 1 2 1; 0 0 0; -1 -2 -1]; | |
sobelm_y = [ -1 0 1; -2 0 2; -1 0 1]; | |
% convolute with sobel kernel | |
w_x = conv2(img, sobelm_x); | |
w_y = conv2(img, sobelm_y); | |
w = sqrt(double(w_x.^2 + w_y.^2)); | |
% imshow(w); | |
imwrite(w, gray(256), 'conv.png'); | |
img = imread('conv.png'); | |
binarized = imbinarize(img); | |
% imshow(binarized); | |
skeletonized = bwskel(binarized); | |
imshow(skeletonized); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment