Info

This question is closed. Reopen it to edit or answer.

image analysis for macrographs

1 view (last 30 days)
Hemant Agiwal
Hemant Agiwal on 13 Nov 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I want to eliminate the area/image/grains present outside the ride zone and keep only the dark contrast region inside the red zone for measurements.
Can anyone suggest ways to do it.
There are multiple images like this and all have similar shapes and I want to elimiate the region outside the red zone.
(i have marked the red line by hand, I need a way to automate this)
This is the original image

Answers (1)

Mark Sherstan
Mark Sherstan on 13 Nov 2018
I would reccomend using the Color Thresholder App (https://www.mathworks.com/help/images/ref/colorthresholder-app.html) which is part of the Image Processing Toolbox. You can load in an image either from a GUI or from your workspace (use imread).
As you want the darker contrasted areas use the HSV color space and adjust the saturation and value until you get the image thresholded for the region you would like.
As there is some noise / the image colors overlap further filter the image with functions such as imfill and bwareafilt. I quickly came up with something that looks like this:
I = imread('image1.jpg');
[BW,maskedRGBImage] = createMask(I);
imshow(maskedRGBImage)
Where the createMask function is autogenerated and is as follows (note I added the further filtering in this function (around line 34) :
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 12-Nov-2018
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 0.997;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.155;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 0.525;
% 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;
% NOT PART OF STANDARD MASKING FUNCTION. ADDED TO FURTHER FILTER IMAGE
BW = imfill(BW, 'holes');
BW = bwareafilt(BW,1);
% 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
The result is:
untitled.png
The image approximetly shows the same area you outlined earilier. With some more time optimizing the channels (the range of HSV values you are filtering the image for) and depending on the rest of your data this method should hopefully answer your question!

This question is closed.

Community Treasure Hunt

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

Start Hunting!