Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need solution how to detect crack on egg's shell

Status
Not open for further replies.

aman1988

New Member
recently, my lecturer given me a task on how to detect crackk on egg shell using matlab (image processing toolbox)
im totally a newbie in this area. i read all forum, learn step by step n i stuck at how to define the region as crackk.
can someone guide me directly cuz due date is near.


View attachment 61932
this image i take using candling method. using a normal white bulb.


View attachment 61933
my last image of boundary


how to make the picture clearer just only views the crackk..

HELP ME! TY
 
can be more specific on how to write a routine to remove the non crack splotches?
i had trouble on how to create the routine.. in my learning, only covered basic about image processing.
 
You need to write code to look for long spots on the egg. It looks like short spots are fine. Long spots are a crack.
 
Hi,

This is a little interesting.

Based on your posted images, i would think the simplest method would be a tracing method where you scan the image in an orderly fashion say left to right and top to bottom looking for a light spot. Once you find a light spot, you follow the pixels in various directions to figure out the length of the spot. If the spot is long enough it's a crack.

Also, you probably wont want to do this but if you bathe the egg in food coloring diluted with water the crack is easier to detect.
 
Last edited:
Looking at the crack; the edges of the crack look sharper than the edges around the spots. Try playing with edge detect, and fine edge detect.
 
It's not such an easy problem, even for someone with experience in 2D video processing algorithms.

If you can eliminate the outer 10% edge of the egg and process only the part directly facing the camera the job gets easier.

Then islanding can remove the majority if small isolated splotches but will probably not be enough processing in total. You may need to add some type of linear feature detection after the islanding process removes most of the splotches.
 
You need to write code to look for long spots on the egg. It looks like short spots are fine. Long spots are a crack.

such as? i mean the code. from my references, my senior does this code to detect dirt.

function dirtDetection_Callback(hObject, eventdata, handles)
global RGB
global total_Area_Live
%invert the binary condition
%bw2 = imcomplement(b);
%imwrite(bw2, 'B3.png');
% Display image in axesImage1.
%axes(handles.axesrgb);
%imshow(bw2);
%clear non-dirt binary
%BWc1 = imclearborder(bw2,4)
%imwrite(BWc1, 'I3.png');
% Display image in axesImage2.
%axes(handles.axesbinary);
%imshow(BWc1), title 'Dirt';

%Measure area of image regions
%STATS = regionprops(BWc1,'PixelList');
%total = bwarea(BWc1);
%if total <= 0
%set(handles.resultdirt,'String','CLEAN EGG');
%else total >= 1
%set(handles.resultdirt,'String','DIRT EGG');
%end
%rgb2gray
gray = rgb2gray(RGB);
%filtering
filter = medfilt2(gray,[3 3])
% Take the red channel.
grayImage = filter:),:,1);
% Find the mask
maskImage = grayImage > 80;
% Shrink it a bit.
maskImage = imerode(maskImage, ones(5));
% Calculate the texture.
textureImage = stdfilt(grayImage);
% It shows the edge of the egg, so mask away the edge.
textureImage = textureImage .* double(maskImage);
% Threshold it and fill it
binaryTexture = textureImage > 10;
binaryTexture = imfill(binaryTexture, 'holes');
binaryTexture = imclose(binaryTexture, ones(9));
binaryTexture = imfill(binaryTexture, 'holes');
% Display the image.
axes(handles.axesrgb);
imshow(grayImage), title('Binary image');
%Measure area of image regions
%STATS = regionprops(binaryTexture);
%Measure dirt of egg regions
hold on;
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using
% the coordinates returned by bwboundaries.
boundaries = bwboundaries(binaryTexture);
numberOfBoundaries = size(boundaries);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary:),2), thisBoundary:),1), 'g', 'LineWidth', 2);
end
hold off;

total_Dirt_Live = bwarea(binaryTexture)
%calculate the percentage of dirt
Percent_Live=(total_Dirt_Live/total_Area_Live)*100
if Percent_Live == 0
set(handles.resultdirt,'String','CLEAN EGG');
else set(handles.resultdirt,'String',round(Percent_Live))

end


so i think to detect crack is very similar to detect dirt but using different technique.
pls give some hint to doing the code.

p/s : this code come with interface, so i only take the dirt part
 
Last edited:
It's not such an easy problem, even for someone with experience in 2D video processing algorithms.

If you can eliminate the outer 10% edge of the egg and process only the part directly facing the camera the job gets easier.

Then islanding can remove the majority if small isolated splotches but will probably not be enough processing in total. You may need to add some type of linear feature detection after the islanding process removes most of the splotches.

dear mr RB, can u give me some hint how to eliminate the outer 10% edge like you said. i mean i need more references.
 
Hi,

This is a little interesting.

Based on your posted images, i would think the simplest method would be a tracing method where you scan the image in an orderly fashion say left to right and top to bottom looking for a light spot. Once you find a light spot, you follow the pixels in various directions to figure out the length of the spot. If the spot is long enough it's a crack.

Also, you probably wont want to do this but if you bathe the egg in food coloring diluted with water the crack is easier to detect.

right now i dun have enough time to thinks. can u teach me?
 
dear mr RB, can u give me some hint how to eliminate the outer 10% edge like you said. i mean i need more references.

I meant to remove the outer edge from all the testing. This can be done by only allowing and using the more central oval area.

I don't want to be rude but it does sound like you want everyone else to do your homework project for you...
 
right now i dun have enough time to thinks. can u teach me?

Hi,

Well first you load the image into memory as a bitmap, 24 bit or 32 bit most likely.
Then you start at the top or bottom row and scan across the row peeking the color pixel values, then the next row, etc., until you've scanned every row. While you are peeking all the color values, you create an array that stores say 128 of the brightest colors, where the array holds the count of those colors found. You then look for the max count and that color becomes your search color or you use several colors if they are nearly the same and you'll search for either of those colors.
You then scan again, looking for groups of pixels that match one of the search colors. If a pixel is adjacent (above, below, left, right, diagonal, etc.) to the current pixel it is considered one of the group. You'll have to figure out how to do this algorithmically.

I actually had to do this once in a program, but instead of searching for patches of grouped pixels of the same color i only had to search for straight lines that were connected forming rectangles. That was a little easier. To do this, i looked at the surrounding pixels and if one of them was the same color that became the next current scan pixel.
You probably have to follow the pixels across and up and down and diagonally and find the greatest path distance between the border pixels, path distance being the sum of individual pixel distances. this wont be super easy to work out, but you should be able to come up with something.
You probably only need the greatest distance across a patch, which could be in any direction and even change direction, but that might not be too hard to do.
 
Last edited:
I meant to remove the outer edge from all the testing. This can be done by only allowing and using the more central oval area.

I don't want to be rude but it does sound like you want everyone else to do your homework project for you...

mr RB. no i want to do it by myself as it is for my future too. what i mean is i need someone who can guide me. hard without any knowledge and experience. btw thanks for ur answer :)
 
Hi,

Well first you load the image into memory as a bitmap, 24 bit or 32 bit most likely.
Then you start at the top or bottom row and scan across the row peeking the color pixel values, then the next row, etc., until you've scanned every row. While you are peeking all the color values, you create an array that stores say 128 of the brightest colors, where the array holds the count of those colors found. You then look for the max count and that color becomes your search color or you use several colors if they are nearly the same and you'll search for either of those colors.
You then scan again, looking for groups of pixels that match one of the search colors. If a pixel is adjacent (above, below, left, right, diagonal, etc.) to the current pixel it is considered one of the group. You'll have to figure out how to do this algorithmically.

I actually had to do this once in a program, but instead of searching for patches of grouped pixels of the same color i only had to search for straight lines that were connected forming rectangles. That was a little easier. To do this, i looked at the surrounding pixels and if one of them was the same color that became the next current scan pixel.
You probably have to follow the pixels across and up and down and diagonally and find the greatest path distance between the border pixels, path distance being the sum of individual pixel distances. this wont be super easy to work out, but you should be able to come up with something.
You probably only need the greatest distance across a patch, which could be in any direction and even change direction, but that might not be too hard to do.

i try 1st. if cant i will ask u again :)
 
Just stumbled across this thread and thought the problem set was quite an interesting one and something that I would not have had much trouble with as a student, but I've nothing to do with matlab.

I have no idea what sort of course aman1988 is doing or what background knowledge he has already learned.

So knowing nothing about matlab I should be able to give you almost direct solutions and not actually do it for you.

The question was put to you, "What differentiates a crack from non-crack ?"
Or, define in mathematical terms what isn't a crack. Calculus is the tool you want.
So I hope you've already covered basic calculus else you might consider going back and learning the basics.

Well any pixel which is surrounded by similiar pixels is not part of a crack.
Where a pixel varies greatly from it's neighbour defines some sort of boundary.
Differentiation of a pixel's luminance or chromonance from it's neighbours either immediate or distant.

You're second image looks like a good start. It doesn't define the edges of the egg, and there are large clusters of pixels in the center which I would consider to be noise. The most obvious part of the crack is there, while the weaker parts are not.

Some simple alogrythms might help eliminate some of the noise. Weighting the pixels. Assigning each pixel weight and then running a "game of life" kind of algorythm over it. eliminate pixels which do not have at least two neighbouring pixels on opposite sides etc.
 
Just stumbled across this thread and thought the problem set was quite an interesting one and something that I would not have had much trouble with as a student, but I've nothing to do with matlab.

I have no idea what sort of course aman1988 is doing or what background knowledge he has already learned.

So knowing nothing about matlab I should be able to give you almost direct solutions and not actually do it for you.

The question was put to you, "What differentiates a crack from non-crack ?"
Or, define in mathematical terms what isn't a crack. Calculus is the tool you want.
So I hope you've already covered basic calculus else you might consider going back and learning the basics.

Well any pixel which is surrounded by similiar pixels is not part of a crack.
Where a pixel varies greatly from it's neighbour defines some sort of boundary.
Differentiation of a pixel's luminance or chromonance from it's neighbours either immediate or distant.

You're second image looks like a good start. It doesn't define the edges of the egg, and there are large clusters of pixels in the center which I would consider to be noise. The most obvious part of the crack is there, while the weaker parts are not.

Some simple alogrythms might help eliminate some of the noise. Weighting the pixels. Assigning each pixel weight and then running a "game of life" kind of algorythm over it. eliminate pixels which do not have at least two neighbouring pixels on opposite sides etc.

ty so much..
now i understand.
im was a mechanical student once.
cont my further study in industrial automation & robotics technology :D
so a bit hard to do anything without any knowledge.
that's y here i seek for guidance :D
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top