Commit a996210c authored by asalgado's avatar asalgado
Browse files

Upload function histogramValues.m

parent 5192f3d8
% function will generate bin, histogram, and return mode,lowerBreak,matrix
function [modeLoc,modeTemp,mode,lowerBreak,pointer1,pointer2,pointer3,histArray,arrayDeri]=histogramValues(matrixIN,gapB)
%Final section: HIstogramWork
%Loop 1 >>>>>>>>>>>>>>>>>>>>>>>GENERATING BINS AND BINNING masked vales
% generating bins and catergorizing the values
%sky is removed all analysis is done only in canopy area
% The edge pixels could mix with sky so, take values above sero for canopy
% matrixIN=masked_crop;
% gapB=1;
%Final section: HIstogramWork
histArray=0;
results=0;
stackR=0;
t_array=0;
% if isempty(gapB)
% gapB=1.0;
% end
bingap=gapB;
minPoint=fix(min(min(matrixIN)));
maxPoint=round(max(max(matrixIN)));
[bins]=minPoint:bingap:maxPoint;
% [bins]=0:bingap:60;
% [bins]=binStart:bingap:binEnd;%the celcius values for each bins (degress 0.5 intervals)
%bin size always better to keep 1 to maintain better seqence of
%decending and ascending values
%the bin values are starting values for each bin
for i1=1:length(bins)
histArray(i1,1)=bins(i1);%bin lable in the 1st col
histArray(i1,2)=0;%the second col for storing results
%iterate over the matrix classifying each pixels into bins
%the selection boundaries are the current bin value upto less than the upper level
for x=1:length(matrixIN(1,:))
for y=1:length(matrixIN(:,1))
if matrixIN(y,x)>=bins(i1) && matrixIN(y,x)<bins(i1)+bingap
histArray(i1,2)=histArray(i1,2)+1; %getting the count of pixels
% histArray(i1,length(histArray(i1,:))+1)=matrixIN(y,x);%also inserting the relevent pixels next to last column
end
end
end
end
% %Loop 2 >>>>>>>>>>>>>>>>>>>STACKING
% %Stacking the thermal values along one column
% %Transpose of the histArray, Only taking histgorams area with values
% %ignore zeros
% results=0;
% stackR=0;
% for a=1:length(bins)
% results(a,1)=bins(a);
% results(a,2)=histArray(a,2);
% results(a,3)=0; %the 3rd col for storing results
%
% %iterating the raw values section in histArray from col 3 onwards
% for b=3:length(histArray(a,3:end))%the colums
% if histArray(a,b)>0
% % results(a,3)=results(a,3)+1;
% if stackR(1,1)==0 %for the starting cell of stackR
% stackR(1,1)=bins(a);%bins
% stackR(1,2)=histArray(a,b);%values
% else %all other in the following rows
% %for storing histArray values in stack way
% stackR(length(stackR(:,1))+1,1)=bins(a);%bins
% stackR(length(stackR(:,1)),2)=histArray(a,b);%values
% end
% end
% end
%
% end
% Loop >>>>>>>>>>>>>>>>>>>>>>>Calculating derivatives
arrayDeri=histArray(:,1:2);
for i1=2:length(arrayDeri(:,1)) %Bcos derivative:deducted from prevouse number start from 2nd point
numerator=(arrayDeri(i1,2)-arrayDeri(i1-1,2));
denominator=(arrayDeri(i1,1)-arrayDeri(i1-1,1));
% %store derivatives into the 3rd col
arrayDeri(i1,3)=numerator/denominator;
end
%Loop 3>>>>>>> Selecting MAX, MODE POINT SELECTION
%Start searching for the points from below of the array
%starting from the left of the histogram towards right
%thats the best way to avoid sky peaks
%if get the mode point that would be best to later split array in two
%100 was generic value after manually scaning
pointer1=0;%Posible upper boundary area,the mark below -100
pointer2=0;%the mode position
pointer3=0;
%iterate until getting the 1st decline
%before it dropps morea than -250
for i2=length(arrayDeri(:,1)):-1:1
if arrayDeri(i2,3)<-100 % search for the forwarding point
% if arrayDeri(i2-1,3)==min(min(arrayDeri))
pointer1=i2; %%%%array subset start
break
end
end
%next positive part where mode will be there
%the first positive from right isfilePath the mode
for i3=pointer1:-1:1 %mode position
%iterate until the next rise
% most negative part
%if arrayDeri(i3-1,3)>arrayDeri(i3,3)
if sign(arrayDeri(i3,3))==1
pointer2=i3;
modeTemp=arrayDeri(i3,1);
mode=arrayDeri(i3,2);
modeLoc=pointer2;
break
end
end
lowerBreak=0;%load the location of break if exists
for i4=pointer2:-1:1 %if there is a sudden rise, break and take that as the
% lowest point of the lower part
if sign(arrayDeri(i4,3))==-1
pointer3=i4; %%stop point for subarray
lowerBreak=arrayDeri(i4,1);
break
else
pointer3=i4;
end
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment