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

답변 (2개)

Steven Lord
Steven Lord 2018년 9월 19일

0 개 추천

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

Dear Steven Lord,
thanks again for your help, your 'DisplayOrder' tip helped me in sorting histogram bins in ascending order.
Best.

댓글을 달려면 로그인하십시오.

Pierre-Olivier BRUNA
Pierre-Olivier BRUNA 2018년 9월 20일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2018년 9월 19일

댓글:

2021년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by