a = dir('*.tif'); whos a Name Size Bytes Class Attributes a 6x1 2590 struct a(1).name ans = background.tif M = cell(6,3); for i=1:6, M{i,1} = a(i).name; M{i,2} = imread(a(i).name); end; for i=2:6, M{i,3} = uint8(abs(double(M{i,2}-double(M{1,2})))); end; ??? Error using ==> minus Integers can only be combined with integers of the same class, or scalar doubles. for i=2:6, M{i,3} = uint8(abs(double(M{i,2})-double(M{1,2}))); end; figure; for i=1:6, subplot(2,3,i); imshow(M{i,2}); end; figure; for i=2:6, subplot(2,3,i); imshow(M{i,3}); end; I = M{2,3}; Ig = rgb2gray(I); figure; subplot(2,2,1); imhist(I(:,:,1); ??? figure; subplot(2,2,1); imhist(I(:,:,1); | Error: Unbalanced or unexpected parenthesis or bracket. figure; subplot(2,2,1); imhist(I(:,:,1)); subplot(2,2,2); imhist(I(:,:,2)); subplot(2,2,3); imhist(I(:,:,3)); subplot(2,2,4); imhist(Ig); t = imthresh(Ig) ??? Undefined function or method 'imthresh' for input arguments of type 'uint8'. help graythresh GRAYTHRESH 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. [LEVEL EM] = GRAYTHRESH(I) returns effectiveness metric, EM, as the second output argument. It indicates the effectiveness of thresholding of the input image and it is in the range [0, 1]. The lower bound is attainable only by images having a single gray level, and the upper bound is attainable only by two-valued images. Class Support ------------- The input image I can be uint8, uint16, int16, single, or double, and it must be nonsparse. LEVEL and EM are double scalars. Example ------- I = imread('coins.png'); level = graythresh(I); BW = im2bw(I,level); figure, imshow(BW) See also im2bw. Reference page in Help browser doc graythresh t = graythresh(Ig) t = 0.2196 t*255 ans = 56 Ig_b = Ig >= 56; figure, imshow(Ig_b); Ig_b = Ig >= 45; figure, imshow(Ig_b); Ig_b = Ig >= 35; figure, imshow(Ig_b); tr2 = graythresh(I(:,:,1)) tr2 = 0.2275 tr2 = graythresh(I(:,:,1))*255 tr2 = 58 tg2 = graythresh(I(:,:,2))*255 tg2 = 53 tb2 = graythresh(I(:,:,3))*255 tb2 = 62 figure, imshow(I(:,:,1) >= tr2); figure, imshow(I(:,:,2) >= tg2); figure, imshow(I(:,:,3) >= tb2); figure, imshow(I(:,:,3) >= tb2/2); figure, imshow(I(:,:,1) >= tr2/2); figure, imshow(I(:,:,2) >= tg2/2); figure, imshow((I(:,:,1) >= tr2/2) | (I(:,:,2)>=tg2/2) | (I(:,:,3)>=tb2) ); Ib = (I(:,:,1) >= tr2/2) | (I(:,:,2)>=tg2/2) | (I(:,:,3)>=tb2); [i1,j1] = find(Ib > 0); rc = sum(i1) / length(i1) rc = 256.4691 cc = sum(j1) / length(j1) cc = 360.0890 help bwmorph BWMORPH Morphological operations on binary image. BW2 = BWMORPH(BW1,OPERATION) applies a specific morphological operation to the binary image BW1. BW2 = BWMORPH(BW1,OPERATION,N) applies the operation N times. N can be Inf, in which case the operation is repeated until the image no longer changes. OPERATION is a string that can have one of these values: 'bothat' Subtract the input image from its closing 'bridge' Bridge previously unconnected pixels 'clean' Remove isolated pixels (1's surrounded by 0's) 'close' Perform binary closure (dilation followed by erosion) 'diag' Diagonal fill to eliminate 8-connectivity of background 'dilate' Perform dilation using the structuring element ones(3) 'erode' Perform erosion using the structuring element ones(3) 'fill' Fill isolated interior pixels (0's surrounded by 1's) 'hbreak' Remove H-connected pixels 'majority' Set a pixel to 1 if five or more pixels in its 3-by-3 neighborhood are 1's 'open' Perform binary opening (erosion followed by dilation) 'remove' Set a pixel to 0 if its 4-connected neighbors are all 1's, thus leaving only boundary pixels 'shrink' With N = Inf, shrink objects to points; shrink objects with holes to connected rings 'skel' With N = Inf, remove pixels on the boundaries of objects without allowing objects to break apart 'spur' Remove end points of lines without removing small objects completely. 'thicken' With N = Inf, thicken objects by adding pixels to the exterior of objects without connected previously unconnected objects 'thin' With N = Inf, remove pixels so that an object without holes shrinks to a minimally connected stroke, and an object with holes shrinks to a ring halfway between the hold and outer boundary 'tophat' Subtract the opening from the input image Class Support ------------- The input image BW1 can be numeric or logical. It must be 2-D, real and nonsparse. The output image BW2 is logical. Examples -------- BW1 = imread('circles.png'); figure, imshow(BW1) BW2 = bwmorph(BW1,'remove'); BW3 = bwmorph(BW1,'skel',Inf); figure, imshow(BW2) figure, imshow(BW3) See also erode, dilate, bweuler, bwperim. Reference page in Help browser doc bwmorph diary off;