Removing an area from an image

6 visualizaciones (últimos 30 días)
Jocko
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.
R7URFS-Segment.jpg
%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
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 ?
Jocko
Jocko el 6 de Feb. de 2019
Kalyan, thanks.
Yes - I think of the images in terms of microns. However yes, that would equate to 220x220 pixels squared. Basically an area less than 48400 pixels squared. I tried various iterations myself but I could not get it to work correctly.
Thanks you again.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
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.
  2 comentarios
Jocko
Jocko el 6 de Feb. de 2019
Hello - your comment made me realise that my numbers are indeed ambiguous.
For the record, yes I want to remove white areas (small cells) in the image which have a total area of 20microns2 or less. Sorry for the ambiguity on my part.
Jocko
Jocko el 7 de Feb. de 2019
@ImageAnalyst - thanks to you, and @Kaylan for your input. I have used ImageAnalyst's method and it got what I required for this piece of the problem.
Now to just sort out my skeletonisation!
Thanks again.

Iniciar sesión para comentar.

Más respuestas (1)

KALYAN ACHARJYA
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
Jocko
Jocko el 6 de Feb. de 2019
I'll give this a go tonight. Just to confirm, I'm sure it's obvious, but the regions are not necessarily square - I'm interested in regions of any shape once they contain 20um2 or less.
So in my case I'd be detecting all "white" areas as opposed to all "square" areas, then applying bwareaopen?
KALYAN ACHARJYA
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!

Iniciar sesión para comentar.

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!

Translated by