Image segmentation with region-based thresholds in Matlab -
i have noisy image multiple separated circular regions blurred out. example of such image 6 region of interests (roi) :
segmenting image global threshold easy in matlab using bwconncomp
, given threshold. want set fix threshold (e.g. 54%) with respect maximum pixel value of every roi (instead of whole image) to segment each roi.
i have collection of images different roi sizes , positions, , need segment them based on regional-based thresholding, therefore cannot use matlab interactive tool select them either.
thanks
after you've done connected component analysis try using bwlabel. label each of 6 regions number 1-6. use each of regions/labels mask. @ values in region , find max
%after bwconncomp lbls = bwlabel(my_bw_conn_output); num_lbls = max(lbls(:)); percentage_of_max = 54; my_thresh = zeros(1,num_lbls); ii=1:num_lbls %isolates 1 roi temp_mask = (lbls == ii); %we 2 maxes, 1 rows 1 columns max_val = max(max(uint8(temp_mask) .* image_with_values_to_threshold)); %this color pictures my_thresh(ii) = percentage_of_max * max_val end
edit
if want use results of bwconncomp directly more this
%my code written assuming started grayscale image, though %could adapt color image cc = bwconncomp(grayscale_image); percentage_of_max = 54; ii=1:cc.numobjects mask = zeros(cc.imagesize); %converts indexes x,y coordinates [x_coords,y_coords] = ind2sub(cc.imagesize,cc.pixelidxlist{ii}(:)); mask(x_coords,y_coords) = 1; %masks image roi_im = bsxfun(@times, uint8(mask), grayscale_image); %% processing region here using roi_im curr_thresh = max(roi_im (:)) * percentage_of_max; thesh_im = grayscale_image > curr_thresh; end
another alternative crop images , run calculations on cropped image. jsut came across post how crop face section image given corner points. matlab helps cropping perfect squares. can use roipoly if have shape isn't rectangle.
Comments
Post a Comment