Categorise and sort an histogram

9 Ansichten (letzte 30 Tage)
Pierre-Olivier BRUNA
Pierre-Olivier BRUNA am 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

Antworten (2)

Steven Lord
Steven Lord am 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 Kommentar
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco am 14 Jun. 2021
Dear Steven Lord,
thanks again for your help, your 'DisplayOrder' tip helped me in sorting histogram bins in ascending order.
Best.

Melden Sie sich an, um zu kommentieren.


Pierre-Olivier BRUNA
Pierre-Olivier BRUNA am 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

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by