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

  • SEARCH
  • Home
  • 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 729595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:48:53+00:00 2026-05-14T06:48:53+00:00

My main question is given a feature centroid, how can I draw it in

  • 0

My main question is given a feature centroid, how can I draw it in MATLAB?

In more detail, I have an NxNx3 image (an RGB image) of which I take 4x4 blocks and compute a 6-dimensional feature vector for each block. I store these feature vectors in an Mx6 matrix on which I run kmeans function and obtain the centroids in a kx6 matrix, where k is the number of clusters and 6 is the number of features for each block.

How can I draw these center clusters in my image in order to visualize if the algorithm is performing the way I wish it to perform? Or if anyone has any other way/suggestions on how I can visualize the centroids on my image, I’d greatly appreciate it.

  • 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-05-14T06:48:53+00:00Added an answer on May 14, 2026 at 6:48 am

    Here’s one way you can visualize the clusters:

    As you described, first I extract the blocks, compute the feature vector for each, and cluster this features matrix.

    Next we can visualize the clusters assigned to each block. Note that I am assuming that the 4×4 blocks are distinct, this is important so that we can map the blocks to their location back in the original image.

    Finally, in order to display the cluster centroids on the image, I simply find the closest block to each cluster and display it as a representative of that cluster.

    Here’s a complete example to show the above idea (in your case, you would want to replace the function that computes the features of each block by your own implementation; I am simply taking the min/max/mean/median/Q1/Q3 as my feature vector for each 4×4 block):

    %# params
    NUM_CLUSTERS = 3;
    BLOCK_SIZE = 4;
    featureFunc = @(X) [min(X); max(X); mean(X); prctile(X, [25 50 75])];
    
    %# read image
    I = imread('peppers.png');
    I = double( rgb2gray(I) );
    
    %# extract blocks as column
    J = im2col(I, [BLOCK_SIZE BLOCK_SIZE], 'distinct');  %# 16-by-NumBlocks
    
    %# compute features for each block
    JJ = featureFunc(J)';                                %'# NumBlocks-by-6
    
    %# cluster blocks according to the features extracted
    [clustIDX, ~, ~, Dist] = kmeans(JJ, NUM_CLUSTERS);
    
    %# display the cluster index assigned for each block as an image
    cc = reshape(clustIDX, ceil(size(I)/BLOCK_SIZE));
    RGB = label2rgb(cc);
    imshow(RGB), hold on
    
    %# find and display the closest block to each cluster
    [~,idx] = min(Dist);
    [r c] = ind2sub(ceil(size(I)/BLOCK_SIZE), idx);
    for i=1:NUM_CLUSTERS
        text(c(i)+2, r(i), num2str(i), 'fontsize',20)
    end
    plot(c, r, 'k.', 'markersize',30)
    legend('Centroids')
    

    clusters
    image

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The main web application of my company is crying out for a nifty set
My main JavaScript framework is jQuery , so I would like my unit test
function main() { Hello(); } function Hello() { // How do you find out
The main user-case is: Create the 2D floor plan See the 3D view of
Why main must be declared as if it has external linkage? Why it should
My main browsers (FF and Chrome) are both configured for a 12 pixel font.
The main jQuery method takes a second optional argument to provide context for the
My main experience is with C && C++, so I'd prefer to remain with
My main window has spawned a child window that's positioned on top to look
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,

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.