Cropping Abnormal Image for Multiple Laboratory Trials

1 visualización (últimos 30 días)
Lauren Smith
Lauren Smith el 15 de Feb. de 2024
Comentada: Shubham el 18 de Mzo. de 2024
Working on a porject that involved cropping a pad image. I can't get the crop just right -- I want the entire pad cropped out of the backround and for it to work for multiple trials and different images -- not just this image. I uploaded 3 samples photos. Thank you!

Respuestas (2)

Shubham
Shubham el 23 de Feb. de 2024
Hi Lauren,
It seems that you are trying to extract the pad and remove the background of the image.
Although it is not possible to crop the pad out of the image, but you can define a region of interest (ROI)” for the same. Upon checking the three images, I am assuming that the position of camera and the relevant objects are not moved in between. In such a scenario, you can create a “ROI” for one image and use it for others. For creating a customizable “ROI”, please refer to the drawpolyon” function: https://www.mathworks.com/help/images/ref/drawpolygon.html
Another approach you could perform would be to remove the background through image segmentation with the help of masking. You can leverage the “Color Thresholder” to create the mask for the image. Have a look at the following documentation: https://www.mathworks.com/help/images/image-segmentation-using-the-color-thesholder-app.html
I have generated the mask using the above method and tested it out on the provided images. You can refer to the following code snippet and output:
image = imread('0ml.png');
[bw,mi] = createMask(image);
imshow(mi)
function [BW,maskedRGBImage] = createMask(RGB)
% Convert RGB image to chosen color space
I = rgb2ycbcr(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 27.000;
channel1Max = 233.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 98.000;
channel2Max = 129.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 128.000;
channel3Max = 210.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
You can use the generated code for masking all the images. You can also crop out the image on the edges using a script. You can use the “imcrop” function for the same:
You can also refer to this post available on MathWorks Blogs which goes through the whole process of background removal: https://blogs.mathworks.com/loren/2015/06/24/how-do-you-modify-the-background-of-an-image/?s_tid=answers_rc2-1_p4_MLT#0e096a30-80d6-40f2-aed4-76996bf2fef1
You may also find the below MATLAB Answers relevant to your query:
I hope this helps!
  2 comentarios
Lauren Smith
Lauren Smith el 27 de Feb. de 2024
Thank you for your help!
Shubham
Shubham el 18 de Mzo. de 2024
Hey @Lauren Smith, If you find the above answer helpful, please mark it as accepted. Thanks!!

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 27 de Feb. de 2024
You can certainly crop out the pad's bounding box to a new image if you need to. Not sure you need to though.
I've worked on exactly this kind of image for over 30 years. I never needed to crop the image though I did classify the image into stain, pad, and background. Then you can measure all kinds of things about the classes.
If you still need help, let me know. If you let me know what city you're working in, I might be able to help substantially more.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by