Based on your existing code:
img = rgb2gray(imread('W1\Writer1_01_02.jpg'));
k = 1:-0.01:0.1;
bins = 1:100 % change depending on your image
% preallocate output - this will be filled with histograms
histout = zeros(length(k),length(bins);
for m = 1:length(k);
bw_normal = im2bw(img, k(m));
bw = imcomplement(bw_normal);
[label,n] = bwlabel(bw);
stats = regionprops(label,img, {'Area'});
A = cell2mat(struct2cell(stats));
histout(m,:) = hist(A,bins);
end
I changed the output of regionprops
to just Area
because it simplifies conversion of the output struct into something that can be read by hist
. Changing from looping through k
to predefining a vector k
and using k(m)
in the loop just makes indexing into histout
a little more straight forward.
You can display with imagesc
and then correct the tick labelling:
imagesc(histout)
colormap('jet')
set(gca,'XTickLabel',bins(get(gca,'XTick')));
set(gca,'YTickLabel',k(get(gca,'YTick')));
xlabel('Area')
ylabel('Threshold')