Image Analysis and MATLAB Jiří Militky
Basic Matlab commands 0.5 0.8 IMREAD Read image from graphics file IMHIST Display histogram of image data. 0.694 GRAYTHRESH Compute global image threshold using Otsu's method. LEVEL = GRAYTHRESH(I) computes a global threshold (LEVEL) that can be used to convert an intensity image to a binary image with IM2BW. LEVEL is a normalized intensity value that lies in the range [0, 1]. GRAYTHRESH uses Otsu's method, which chooses the threshold to minimize the intraclass variance of the thresholded black and white pixels. IMSHOW Display image. imshow(im2bw(bw,.8))
Basic Matlab commands bw=imread('pad105.jg') imshow(rgb2gray(bw),[100 180]) IMCOMPLEMENT Complement image. IM2 = IMCOMPLEMENT(IM) computes the complement of the image IM. IM can be a binary, intensity, or truecolor image. In the complement of a binary image, black becomes white and white becomes black. RGB2GRAY Convert RGB image or colormap to grayscale. IMADJUST Adjust image intensity values or colormap. J = IMADJUST(I) maps the values in intensity image I to new values in J such that 1% of data is saturated at low and high intensities of I. This increases the contrast of the output image J.
Basic Matlab commands IMTOPHAT Perform top hat filtering using the structuring element SE, IMBOTHAT Perform bottom hat filtering. using the structuring element SE. IMEXTENDEDMIN Extended-minima transform which is the regional minima of the H-minima transform. IMIMPOSEMIN Impose minima. Modifies the intensity image I using morphological reconstruction so it only has regional minima wherever BW is nonzero. BW is a binary image the same size as I.
Basic Matlab commands IMOPEN Open image. IM2 = IMOPEN(IM,SE) performs morphological opening on the grayscale or binary image IM with the structuring element SE. BW2 = IMFILL(BW1,'holes') fills holes in the input image. A hole is a set of background pixels that cannot be reached by filling in the background from the edge of the image. D = BWDIST(BW) computes the Euclidean distance transform of the binary image BW.
Basic Matlab commands WATERSHED Find image watershed regions. Computes a label matrix identifying the watershed regions of the input matrix A. REGIONPROPS Measure properties of image regions.
Example Ia Separation of individual fibers and computation of cross section distribution Puvodni clc;clear all;warning off MATLAB:conversionToLogical; BW = imread('hed.tif'); figure, imshow(bw), title( Original') I = rgb2gray(bw); I = imadjust(im2double(i), [], [0 1]); se = strel('disk', 5); Itop = imtophat(i, se); Ibot = imbothat(i, se);
Example Ib Morphological filters top-hat trans bottom-hat trans figure, imshow(itop, []), title('top-hat trans'); figure, imshow(ibot, []), title('bottom-hat trans');
Example Ic Enhancement Morphological reconstruction puvodni + top-hat - bottom-hat Ienhance = imsubtract(imadd(itop, I), Ibot); figure, imshow(ienhance), title('puvodni + top-hat - bottomhat'); Iec = imcomplement(ienhance); Iemin = imextendedmin(iec,.49); Iimpose = imimposemin(iec, Iemin);
Example Id Watershed watershed objekty wat = watershed(iimpose); rgb = label2rgb(wat); figure, imshow(rgb); title('watershed objekty');
Example Ie Cross section pdf 3.5 x 10-3 Density estimate cross section area 3 stats = regionprops(wat, 'all'); [nn n]=size(stats); for i=1:nn ar(i)=(stats(i). Area); end ar=sort(ar);ar=ar(1:end-1); [f,x] = ksdensity(ar); plot(x,f); title('density estimate cross section area') 2.5 2 1.5 1 0.5 0 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700
Example IIa % Example of single combination of commands clc;clear all;warning off MATLAB:conversionTo Logical; cbw = imread('hed.tif'); figure, imshow(cbw), title('original') gbw=rgb2gray(cbw); figure,imshow(gbw);, title('gray transform'
Example IIb figure,imhist(gbw);, title('gray histogram') level = graythresh(gbw); bw= im2bw(gbw,level); figure,imshow(bw), title('thresholding') bw=1-bw;figure, imshow(bw), title('bw complement')
Example IIc se=ones(3,3);%structural element bwco = imopen(bw, se);figure, imshow(bwco), title('opening') Ifil=imfill(bwco);figure, imshow(ifil), title('filling') D = bwdist(~ifil); figure, imshow(d,[],'initialma gnification','fit') title('distance transform of ~bw')
Example IId D = -D; D(~Ifil) = - Inf;L = watershed(d); rgb = label2rgb(l,'jet',[.5.5.5]); figure, imshow(rgb,'initialmag nification','fit') title('watershed transform ') for i=1:nn ar(i)=(stats(i). Area); end ar=sort(ar);ar=ar(1:end- 1); [f,x] = ksdensity(ar); figure,plot(x,f); title('density estimate cross section area') figure,hist(ar,12);