Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:33:53+00:00 2026-06-04T21:33:53+00:00

I am working on thumb recognition system. I need to implement KNN algorithm to

  • 0

I am working on thumb recognition system. I need to implement KNN algorithm to classify my images. according to this, it has only 2 measurements, through which it is calculating the distance to find the nearest neighbour but in my case I have 400 images of 25 X 42, in which 200 are for training and 200 for testing. I am searching for few hours but I am not finding the way to find the distance between the points.

EDIT:
I have reshaped 1st 200 images in to 1 X 1050 and stored them in a matrix trainingData of 200 X 1050. similarly I made testingData.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:34:00+00:00Added an answer on June 4, 2026 at 9:34 pm

    Here is an illustration code for k-nearest neighbor classification (some functions used require the Statistics toolbox):

    %# image size
    sz = [25,42];
    
    %# training images
    numTrain = 200;
    trainData = zeros(numTrain,prod(sz));
    for i=1:numTrain
        img = imread( sprintf('train/image_%03d.jpg',i) );
        trainData(i,:) = img(:);
    end
    
    %# testing images
    numTest = 200;
    testData = zeros(numTest,prod(sz));
    for i=1:numTest
        img = imread( sprintf('test/image_%03d.jpg',i) );
        testData(i,:) = img(:);
    end
    
    %# target class (I'm just using random values. Load your actual values instead)
    trainClass = randi([1 5], [numTrain 1]);
    testClass = randi([1 5], [numTest 1]);
    
    %# compute pairwise distances between each test instance vs. all training data
    D = pdist2(testData, trainData, 'euclidean');
    [D,idx] = sort(D, 2, 'ascend');
    
    %# K nearest neighbors
    K = 5;
    D = D(:,1:K);
    idx = idx(:,1:K);
    
    %# majority vote
    prediction = mode(trainClass(idx),2);
    
    %# performance (confusion matrix and classification error)
    C = confusionmat(testClass, prediction);
    err = sum(C(:)) - sum(diag(C))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get this sql query working: SELECT TOP 15 id, thumb, width,
I have a working script like this: jQuery(document).ready(function(){ $('.video-thumb img').bind('mouseover',function(){ var new = $(this).attr('src').replace(/default.jpg/,'1.jpg');
I am working on a project thumb recognition. following is code I am reading
Working on a project where I need to add points to an array. Here
Are there any rules of thumb when working with Objective-C that would help me
im working on jquery script to show rollover , now i need to show
I'm working on a site which uses Wordpress and a lot of images. These
I'm currently working through O'Reilly's Programming PHP and have come across this table titled
I am working on an image upload site. When the user uploads the images
I'm working on adapting a jQuery slider that originally had 10 thumbnails. I only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.