Removing an area from an image
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jocko
el 6 de Feb. de 2019
Comentada: Jocko
el 7 de Feb. de 2019
Hi - I'm looking to segment, calculate area and skeletonise a microscope image. I've gotten my segmentation working pretty ok (thanks to some threads I read by Image Analyst), and now want to remove particles in the image smaller that a certain size. I know the pixel dimensions of the image, and I have a scalebar, but how do I start referencing the image size in terms of micrometres instead of pixels? The image is 4140x3096 pixels, equalling 11 pixels per micrometer, and I wish to remove objects smaller than 20 micrometer squared.
Thanks in advance for any assistance or pointers.
I attach the image, and my current code below.

%Call HSVMask function, and assign result to img_segmented
Inimage=imread('R7URFS.jpg');
figure, imshow(Inimage);title('Original Image');
img_segment=HSVMask(Inimage); % call function HSVMask()
imwrite(img_segment,'R7URFS-Segment.jpg');
%figure, imshow(img_segment);title('Segmented Image Returned From Function (HSVMask)');
img_segment=imread('R7URFS-Segment.jpg');
img_gray=rgb2gray(img_segment);
figure, imshow(img_gray);title('Grayscale Segmented Image');
% Shrink and dilate the image
shrinkxtimes=28;
dilatextimes=15;
img_thin_x = bwmorph(img_gray, 'shrink', shrinkxtimes);
%figure,imshow(img_thin_x);title('Shrunk Image');
img_thin_dilated=bwmorph(img_thin_x, 'dilate', 1);% dilate the lines to connect broken parts.
%figure,imshow(img_thin_dilated);title('Dilated Image x1');
%[img_small_removed]=remove_small_objects(img_thin_dilated,4148.916); % call function remove_small_objects
%figure,imshow(img_small_removed);title('Small Parts Removed - Returned from Function (remove_small_objects)');
img_thin_dilated_2=bwmorph(img_thin_dilated, 'dilate', dilatextimes);
%figure,imshow(img_thin_dilated_2);title('Dilated Again x15');
se=strel('disk',10);
img_thin_dilated_2=imfill(img_thin_dilated_2,'holes');
img_thin_dilated_2=imopen(img_thin_dilated_2,se);
Ls=Zheng_Skeletonise(img_thin_dilated_2);
img_skeleton=bwmorph(Ls, 'dilate', 2);
figure,imshow(Ls);title('Complete Skeletonised Image');
imwrite(Ls,'R7URFS-Skeleton.jpg');
return
2 comentarios
KALYAN ACHARJYA
el 6 de Feb. de 2019
qualling 11 pixels per micrometer, and I wish to remove objects smaller than 20 micrometer squared.
What I have undestood from your above text, you want to remove those region having less than 220x220 pixels, please correctify ?
Respuesta aceptada
Image Analyst
el 6 de Feb. de 2019
Please define "20 micrometer squared".
Is it 20 microns by 20 microns = 400 microns^2 ?
Or is if 20 microns^2 ?
I find your description ambiguous.
Try this:
pixelsPerMicron = 11;
minAcceptableAreaInSqMicrons = 20 * 20; % 20 microns by 20 microns, or just 20???
minAcceptableAreaInPixels = minAcceptableAreaInSqMicrons * pixelsPerMicron ^ 2;
binaryImage = bwareafilt(binaryImage, [minAcceptableAreaInPixels, inf]);
Replace binaryImage with whatever variable you want to operate on. You might want to have the min acceptable width of a particle be an edit field or slider on your GUI so the user can adjust it. For example
minWidth = str2double(handles.edtMinWidth.String);
minAcceptableAreaInSqMicrons = minWidth * minWidth; % Apply user's setting.
Más respuestas (1)
KALYAN ACHARJYA
el 6 de Feb. de 2019
Editada: KALYAN ACHARJYA
el 6 de Feb. de 2019
BW2=bwareaopen(binary_image,size_pixel);
%Resultant image having only more than size_pixels area
% But it does not look for shape of the regions
Have you look at the folowing functions? Matlab
The function ismember is useful with regionprops, bwconncomp, and labelmatrix for creating a binary image containing only objects or regions that meet certain criteria.
4 comentarios
KALYAN ACHARJYA
el 6 de Feb. de 2019
Editada: KALYAN ACHARJYA
el 6 de Feb. de 2019
As you stated that region can any shape, then directly apply the following
BW2=bwareaopen(binary_image,size_pixel);
Good Wishes!
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!