필터 지우기
필터 지우기

画像を教師なしで分類する方法

조회 수: 1 (최근 30일)
cho hunseki
cho hunseki 2024년 2월 2일
편집: Atsushi Ueno 2024년 2월 3일
jpgのn個の画像データを教師なしで2つのグループに分類するために、
以下のcodeを準備しました。しかし、エラーが出て対応に困っております。
ご教授頂ければ幸いです。
仮にn個の「〇」と「✖」の画像を2つに分類する場合としました。
【code】
imageFiles = dir('*.jpg'); %
numImages = length(imageFiles);
images = cell(1, numImages);
for i = 1:numImages
currentFilename = fullfile(imageFiles(i).folder, imageFiles(i).name);
images{i} = imread(currentFilename);
end
numPixels = size(images{1}, 1) * size(images{1}, 2);
featureMatrix = zeros(numImages, numPixels, 3); %
for i = 1:numImages
featureMatrix(i, :, :) = reshape(images{i}, numPixels, 3);
end
% k-means
numClusters = 2; %
[idx, centroids] = kmeans(reshape(featureMatrix, [], 3), numClusters);
%
cluster1Indices = find(idx == 1);
cluster2Indices = find(idx == 2);
%
figure;
for i = 1:length(cluster1Indices)
subplot(2, length(cluster1Indices), i);
imshow(images{cluster1Indices(i)});
title(['Cluster 1 - Image ', num2str(i)]);
end
for i = 1:length(cluster2Indices)
subplot(2, length(cluster2Indices), length(cluster1Indices) + i);
imshow(images{cluster2Indices(i)});
title(['Cluster 2 - Image ', num2str(i)]);
end
【エラーメッセージ】
インデックスが配列要素数を超えています。インデックスは 6 を超えてはなりません。
エラー: untitled (34)
imshow(images{cluster1Indices(i)});
宜しくお願い致します。
  댓글 수: 2
Atsushi Ueno
Atsushi Ueno 2024년 2월 3일
  • cluster1Indices + cluster2Indices = (1枚目の画像の画素数) です
  • numImages = (画像の枚数、ここでは6枚) です
画像が6枚しかないのに、cluster1Indices枚目の画像を表示しようとしているので上記エラーが出ています。
Atsushi Ueno
Atsushi Ueno 2024년 2월 3일
편집: Atsushi Ueno 2024년 2월 3일
k = 2 クラスターで全画像の画素値を2分しても「分類結果がどの画像に紐付くか」の情報は持っていません。

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 イメージを使用した深層学習에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!