Extract object from image

3 Ansichten (letzte 30 Tage)
Sara Antonio
Sara Antonio am 14 Jun. 2017
Kommentiert: Image Analyst am 5 Jan. 2019
Hello, I have a big set of images where I'm trying to automatically extract the object (a pebble) from a noisy background into a binary image in order to get the properties of that same object. Annexed I have an example of one of the images I have. What I manage to do was to transform the RGB image to a greyscale image, then adjust the image contrast in order to try to homogenize the pixel intensity on the pebble and then transform into binary. The problem is that the image contrast is not ideal since it doesn't adjust very well to the shadow part of the pebble and gives me a lot of noise from the background. Also, the contrast adjust interval changes with the different images. Is there a more precise way I can extract the pebble from the image?
  2 Kommentare
N.Akila Nehru
N.Akila Nehru am 5 Jan. 2019
Please can anyone tell me how to extract food items from colored image
Image Analyst
Image Analyst am 5 Jan. 2019
Possibly. Read this link and post your new question in a new thread along with your image(s).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jatin Waghela
Jatin Waghela am 21 Jun. 2017
Bearbeitet: Jatin Waghela am 21 Jun. 2017
Suggestions:
You could maybe do some smoothing or other convolution to try to get rid of background gridlines.
To get rid of the big yellow thing, maybe specific filtering on the individual color layers, then excluding that part before doing further processing in grayscale.
The new "imbinarize" has adaptive thresholding, which can help deal with the background changing intensity within the same image.
Using automatic thresholding at all should help deal with the background changing intensity every image.
As an alternative consider using the Watershed segmentation demo in which there is a possibility of splitting up the objects in the image. Please refer to the below link for your reference.
Also, please find an example attached here.
close all clear
%% read and crop image I = imread('DSCF5099.JPG'); I = rgb2gray(I); %convert to grayscale
% Left-click and drag to make bounding box, right-click to crop % I = imcrop(I); % currently you crop by hand but can be set to specific values, look at doc for 'imcrop'
figure subplot(2,2,1) title('Original Image') imshow(I); %show cropped image
%% create binary image and remove noise/fill holes % BW = imbinarize(I); %convert to binary image BW = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);
se = strel('disk',3); BW = imclose(BW,se); %fill small holes se = strel('disk',75); BW = imopen(BW,se); %remove noise se = strel('disk',100); BW = imclose(BW,se); %fill big holes
subplot(2,2,2) title('Regions') imshow(BW)
%% find white regions in BW image cc = bwconncomp(BW)
%% find 2nd largest region numPixels = cellfun(@numel,cc.PixelIdxList); [biggest,idx] = max(numPixels); [secondBiggest] = max(numPixels(numPixels~=biggest)); idx2 = find(numPixels==secondBiggest);
%% find corresponding data in the original image mask = uint8(zeros(size(I))); mask(cc.PixelIdxList{idx2}) = 1; %create mask from largest region maskedI = I.*mask; % convert anything not in the area to black
subplot(2,2,3) title('Masked Image (black)') imshow(maskedI)
maskedI2 =maskedI; maskedI2(mask == 0) = 255;
subplot(2,2,4) title('Masked Image (white)') imshow(maskedI2)

Community Treasure Hunt

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

Start Hunting!

Translated by