Categorise and sort an histogram

10 vues (au cours des 30 derniers jours)
Pierre-Olivier BRUNA
Pierre-Olivier BRUNA le 19 Sep 2018
Hi All
I have an image (attached) that I would like to analyse - namely I would like to know the length in pixels of each of the labelled componnent in my image. I want to be able to separate isolated objects from the connected ones.
so far I have this piece of code that allows me to identify in my image the different objects and to label them.
clc
clear all
close all
%%Connectivity calculation pixels to pixels
% read image and display
A = imread('DFN_TEST_2.pgm');
figure(1)
imagesc (A)
colorbar
%%Initialise the colour of the regions
B = 255-A;
figure, imshow(B); title ('complemented image in grayscale')
%%Compute the cluster identification function
C = bwlabel(B);
% display the labelled image
figure, imshow(C), title('labelled image bw')
vislabels(C), title('each object labelled')
%%Extract objects by area
D = regionprops(C, 'Area');
E = [D.Area];
F = sort(E, 'descend');% Sort in descending order
%%Create histogram
G = histogram(C,[1:8]);
xlabel('Label of connected objects')
ylabel('Pixel length')
title('Length of connected objects')
I was able to produce this histogram:
Now I would like to: 1/ make each bar of the histogram corresponding to 1 object (cf the first (higest) bar is object 1, the second is object 2...)
2/ I want to reorder the bars from the longest pixel length to the shortest ( object 1 will be first, then object 8, object 5...) - I went to this page (https://nl.mathworks.com/help/matlab/creating_plots/control-categorical-histogram-display.html) but it seems that the DisplayOrder stuff is not working /I do not know how to make it work
NB I propose here an example with 8 object but usually I am working with thousands of objects...
Can you give me a hand concerning this issue ?
Thank you in advance

Réponses (2)

Steven Lord
Steven Lord le 19 Sep 2018
The options listed on the documentation page to which you linked that allow you to control how a categorical histogram orders the bins won't work for your application for two reasons.
  1. Those name/value pairs were introduced in release R2017a while the Release for this Answer indicates you're using release R2016b.
  2. The data you're passing into histogram as the first input is not a categorical array.
In order to use 'DisplayOrder' with histogram you would need to upgrade to release R2017a or later and make your data categorical.
  1 commentaire
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco le 14 Juin 2021
Dear Steven Lord,
thanks again for your help, your 'DisplayOrder' tip helped me in sorting histogram bins in ascending order.
Best.

Connectez-vous pour commenter.


Pierre-Olivier BRUNA
Pierre-Olivier BRUNA le 20 Sep 2018
Dear Steven I cannot update my Matlab version is there an alternative way to do what I want to? Also can you explain me how to categorise my data in 2016b? Thank you in advance

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by