Hello, I am having problems with blockproc.
I have an black image with white spots that I want to basic threshold locally rather than globally – that is to perform a basic threshold on tiles.
IM=double(getimage(handles.axes4)); [rows,cols]=size(IM); %Get image from axes component
IM=IM-min(IM(:)); %Background subtract
% Number of tiles or chunks you want it divide up into.
xtiles =4; ytiles= 4; %Numbers pixels per tile to maintain integer number of tiles
nx=floor(cols/xtiles); ny=floor(rows/ytiles);
Call my "LocallythresholdImage" function to define a level for binarising the image where
level = average + 2* standard deviations of the image
centroids=LocallythresholdImage(IM,nx,ny,f) %f=2 i.e. number of standard deviatins above the average
function centroids=LocallythresholdImage(IM,m,n,f)%Uses the thresh function below and then creates a binary image using local
%threshold of size mxn. I
IM=double(IM); %make sure its a double
%Use blockproc uses my "thresh" function
myfun = @(block_struct) thresh3(block_struct.data,f); % myfun = @(block_struct) thresh2(block_struct.data,f);
%I2 = blockproc(Orig,[200 200],myfun,'BorderSize', [3 3], 'TrimBorder', true);
centroids = blockproc(IM,[m n],myfun,'BorderSize', [3 3], 'TrimBorder', true);function [centroids]=thresh3(IM,f)%n=str2num(get(handles.editThreshn,'String'));
%Thresholds image based on mean and S.D.
image=double(IM)-min(IM(:)); threshold=mean(image(:)) + f*std(image(:)); lessThanThreshold = image < threshold; imageThresholded = image; imageThresholded(lessThanThreshold) = 0; regmax = imregionalmax(imageThresholded); s = regionprops(regmax,double(image), 'WeightedCentroid'); format bank centroids = cat(1, s.WeightedCentroid);
for each tile, the centroids are calculated correctly, but in my top level function "centroid=LocallythresholdImage(IM,nx,ny,f) ", centroids is empty
Best Answer