How can I concatenate multiple histograms in a for loop into 1 histogram using matlab

3 views (last 30 days)
I am new to MATLAB. I have calculated 25 histograms using imhist function, which are created from subdividing the image into 25 blocks (1block=1histogram) using for loop. How can I concatenate these histograms on the same graph to make one histogram where for instance, the histogram for the first block stretches on the x axis from 0 to 255, the histogram for the second block stretches from 256 to 511, and so on until the 25th block. How can I do this?
I had found a solution like this https://stackoverflow.com/questions/30951480/how-to-concatenate-3-histograms-on-the-same-graph-in-matlab but my problem is I calculated all 25 histograms using for loop and I don't know what variable should I pass so that I can concatenate all histograms in 1 long histogram as I want it to be.
This is what I had done:
%declare variable
B=12; %B represent the block size
overlapp=3; %overlapping block is slid by 3 pixels along the image
nob=0; %no of blocks
%get input from grayscale image
gray_path = 'D:\gray_image_folder\*.png';
total_gray_images=dir(gray_path);
for noOfGRAYimage = 1:length(total_gray_images)
% Specify images names with full path and extension
grayfilename=strcat('D:\gray_image_folder\', total_gray_images(noOfGRAYimage).name);
grayImage = imread(grayfilename);% Read gray images
[r, c, p]=size(grayImage);
for i=1:overlapp:(r-B)+1;
% fprintf('i = %d\n', i);
% numberofblock = sprintf('%s_%d','block',nob)
for j=1:overlapp:(c-B)+1;
% fprintf('j = %d\n', j);
nob=nob+1;
fy_mad(nob).block=grayImage(i:i+B-1,j:j+B-1); %partition (12x12) of blocks
fy_mad(nob).position=[i j];
fy_mad(nob).index=nob;
[rb, cb]=size(fy_mad(nob).block); %[12,12]
localBinaryPatternImage = fy_mad(nob).block;
%call function LBP
LBP_centre = LBP (localBinaryPatternImage);
figure;imhist(uint8(LBP_centre)) %histogram for each block
% How to concatenate all histograms?
%////
end
end
end
  4 Comments
jasmine htwe
jasmine htwe on 30 Nov 2017
Edited: Image Analyst on 30 Nov 2017
But, I am not sure which allBinLocs do you use in code?
allBinLocs = [allBinLocs; binLocs(:) + length(allBinLocs)];
Or
allBinLocs = (0:256*numBlocks-1)
And the other question is "stem is same with histogram value or not"?
I am also trying to concatenate histograms.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Aug 2017
See my attached local binary image program.

Community Treasure Hunt

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

Start Hunting!