Image processing using knn
8 views (last 30 days)
Show older comments
Theodora Chivu
on 8 May 2020
Answered: Image Analyst
on 8 May 2020
I have 3 images that I have to label using the knn algorithm and another 18 images that i know. I don't know how to label those 18 img using a variable 18x1 named etichete and don't know how to classificate them using the knn. ext_auto is the function for maximum contrast extension. And it doesn't show hist1,hist2, hist3.
- maximum contrast extension, adaptive variant
- histogram calculation
- patient identification using the algorithm for classifying the closest k-neighbors (k-nearest neighbor - knn), the comparison will be made at the histogram level.
img1 = imread('img34.png');
img2 = imread('img35.png');
img3 = imread('img36.png');
img1 = ext_auto(img1,1);
img2 = ext_auto(img2,1);
img3 = ext_auto(img3,1);
hist1 = histogram(img1,'Normalization','probability');
hist2 = histogram(img2,'Normalization','probability');
hist3 = histogram(img3,'Normalization','probability');
figure,
subplot(2,3,1), imshow(hist1);
subplot(2,3,2), imshow(hist2);
subplot(2,3,3), imshow(hist3);
locatie = 'C:\Users\User\Desktop\Facultate\Anul III\Semestrul II\tsim\Tema2\antrenare';
files=dir(fullfile(locatie, '*.png'));
load('etichete.mat');
h = zeros(length(files),256);
for i = 1:length(files)
FileName = fullfile(locatie, files(i).name);
img = imread(FileName);
img = ext_auto(img,1);
hist = histogram(img,'Normalization','probability');
figure(i), imhist(img);
end
0 Comments
Accepted Answer
Image Analyst
on 8 May 2020
You can't use imshow on a histogram object. You need to use plot() or bar():
counts = hist1.Values;
binCenters = (hist1.BinEdges(1:end-1) + hist1.BinEdges(2:end)) / 2;
bar(binCenters, counts);
xlabel('Gray Level', 'FontSize', 15);
ylabel('Counts', 'FontSize', 15);
Warning: If your image is RGB, the counts are of all the gray levels, regardless of what color channel they're in!
0 Comments
More Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!