function amygedge(F,Jw,final,LOthreshold,plotting,rim)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CODE FOR TESTING ONLY. IS NOT PART OF THE IMPROC SUITE
% detects edge of amydales to fill them uniformally
%http://www.mathworks.com/products/image/demos.html?file=/products/demos/sh
%ipping/images/ipexcell.html
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img=Jw;%imread('edge.bmp');
seism=F;%imread('messy.bmp');
orig=final;%imread('orig.bmp');
figure,subplot(331),imshow(img);
%detect edges using Sobel algorithm
[junk threshold] = edge(img, 'sobel');
fudgeFactor = .5;
BWs = edge(img,'sobel', threshold * fudgeFactor);
subplot(332), imshow(BWs)
%dilate the image
se90 = strel('line', 4, 90);
se0 = strel('line', 4, 0);
BWsdil = imdilate(BWs, [se90 se0]);
J=BWsdil;
subplot(333), imshow(BWsdil);
%remove boundary
J=roiset(J,rim);
subplot(334),imshow(J)
%first fill
BWdfill = imfill(J, 'holes');
subplot(335), imshow(BWdfill);
%second fill
se=strel('disk',6);
closebw=imclose(BWdfill,se);
subplot(336),imshow(closebw);
%morphological closing (cleans edges of amygdales)
img2=imfill(closebw,'holes');
subplot(337),imshow(img2);
%morphological opening: remove snowflakes
se = strel('disk',6);
F = imopen(img2,se);
subplot(338),imshow(F);
%erode image to couteract the dilation
F = imerode(F, [se90 se0]);
%detect rounded objects
F = rounded(F,LOthreshold,plotting);
%find perimeter
b=bwperim(F);
%overlap perimeter on original image to compare
img(find(b==1))= 256;
subplot(339),imshow(img);
figure
subplot(141),imshow(img)
title('original w/ auto detect boundaries')
subplot(143),imshow(F)
title('auto edge detect')
subplot(144),imshow(seism)
title('seismic processing')
subplot(142),imshow(orig)
title('original w/ seismic boundaries')
