Search code examples
imagematlabplotcoordinatesmedian

Plotting median of an image on image coordinates


I have a gray scale image. I want to plot the median of the columns of that image on to the image axis. For doing this I need to have two things:

  1. median values of the columns (which i can obtain using the Matlab's Median command) and
  2. the position of median value in image coordinate.

Can anyone help me or give a hint or an idea or any function for estimating the median position?


Solution

  • This code marks all gray-scale level values in a given column equal to median value for that column:

    load clown
    
    
    M = median(X, 1);
    
    figure();
    imshow(uint8(X));
    hold on;
    
    for columnIdx = 1:numel(M)
        medianValue = M(columnIdx);
    
        % find locations of gray-scale lavel values equal to the median        
        idx = find(X(:, columnIdx) == medianValue);
    
        if numel(idx) > 0
            % mark all the gray-scale level values on the image
            plot(ones(1,numel(idx)) * columnIdx, idx, '.g');
        end
    
    end
    

    enter image description here

    Hope it helps