Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
image processing toolbox

Subject: image processing toolbox

From: Alex

Date: 27 May, 2010 10:44:04

Message: 1 of 15

Recently I'm working on a project about hole identification and positioning with MATLAB , for this mean I use IPT toolbox, the process is simple I take a picture with camera send it to Pc and then start the process.

After changing the picture from RGB to binary type I used some adjustments for background (contarst,etc.)then morphological tools used , e.g. delation and then an erosion, the structuring elements are same ( both are disk with equal radius). this process called closing. Now the problem is disk situation after closing , the lines around are not equal and it is not a complete circle , I have tested different boundary and perimeter functions as well as some filters and reconstruction, they did not help .

if you have some ideas I would be glad to hear them, thank you in advance for your help.

Subject: image processing toolbox

From: Sean

Date: 27 May, 2010 14:52:03

Message: 2 of 15

"Alex " <ashkandav@yahoo.com> wrote in message <htlidk$ohv$1@fred.mathworks.com>...
> Recently I'm working on a project about hole identification and positioning with MATLAB , for this mean I use IPT toolbox, the process is simple I take a picture with camera send it to Pc and then start the process.
>
> After changing the picture from RGB to binary type I used some adjustments for background (contarst,etc.)then morphological tools used , e.g. delation and then an erosion, the structuring elements are same ( both are disk with equal radius). this process called closing. Now the problem is disk situation after closing , the lines around are not equal and it is not a complete circle , I have tested different boundary and perimeter functions as well as some filters and reconstruction, they did not help .
>
> if you have some ideas I would be glad to hear them, thank you in advance for your help.

You're going to have to show us a picture and give a more detailed description of what you want to to with the closed image. Put the image on a free hosting site.

Subject: image processing toolbox

From: ImageAnalyst

Date: 27 May, 2010 17:16:56

Message: 3 of 15

Alex:
I don't understand what you're describing. A "dilation" (not
delation) followed by an erosion on the output image is the same as a
morphological closing operation, which is done by the function
"imclose()" of the Image Processing Toolbox.

Now, what is this disk you're talking about? The "holes" in your
subject (probably not), or the structuring element (probably). Not
sure what you mean by "the disk situation after closing." As you
know, it's digital so the smaller the disk (circle) is the
"chunkier" (more discrete) it will look. A 3 pixel diameter circle
will not appear as smooth as a 300 pixel circle.

I also do now know what it means when you say that you "have tested
different boundary and perimeter functions." No clue at all what this
means.
Why don't you post an image and some code.

Subject: image processing toolbox

From: Alex

Date: 31 May, 2010 13:41:03

Message: 4 of 15

well here I give detaiedl info and some pics,

the first picture taken by microscope is shown here:
http://i47.tinypic.com/25ztc0x.jpg

I am inetersted in locating the hole (here there is only one in center) and then finding its position related to some arbitrary coordiante system and then finding it's diamater and some other parameters.

After changing the picture to binary (black and white) in order to prepare for boundary tracing and etc. I reached to this image:

http://i49.tinypic.com/6z5ukx.jpg

here you can see the codes :


I =imread('1n.jpg');
imshow(I)
SE=strel('disk',20);
level= graythresh(I);
% level=0.5;
I2=im2bw(I,level); % binary version
figure,imshow(I2);
b = double(I2)
I3=imclose(I2,SE); %background #
figure, surf(double(I3(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse'); % background approxiamtion surface
[labeled,numObjects] = bwlabel(I3,4);
numObjects
figure, imshow(labeled);
impixelregion
graindata = regionprops(labeled,'basic')
maxArea = max([graindata.Area])
maxCentroid= max([graindata.Centroid])
maxBoundingBox=max ([graindata.BoundingBox])
biggestGrain = find([graindata.Area]==maxArea)


the histogram is shown here as well:

http://i46.tinypic.com/2e1ztli.jpg

after closing( dilation and the erosion) I have this final picture :

http://i49.tinypic.com/10gi80z.jpg

Now the question is what can i do to enhance the boundary of this circle and reach a full disk, I have tought maybe the picture quality is poor becasue of illumination or other things.

Subject: image processing toolbox

From: ImageAnalyst

Date: 31 May, 2010 19:36:53

Message: 5 of 15

Not sure what your second and third pictures are all about. Why don't
you just use standard image processing methods like this that I
adapted from my image analysis demo at http://www.mathworks.com/matlabcentral/fileexchange/25157


clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
folder = 'C:\Documents and Settings\username\My Documents\Temporary
stuff';
fullFileName = fullfile(folder, '25ztc0x.jpg');
rgbImage = imread(fullFileName);
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original RGB Image', 'fontSize', fontSize);

% Extract the red channel.
grayImage = rgbImage(:,:,1);
subplot(2, 2, 2);
imshow(grayImage, []);
title('Original Grayscale Image', 'fontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

binaryImage = grayImage < 78;
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'fontSize', fontSize);

% Fill holes
filledImage = imfill(binaryImage, 'holes');
% Get rid of blobs smaller than 1000 pixels.
filledImage = bwareaopen(filledImage, 1000);
subplot(2, 2, 4);
imshow(filledImage, []);
title('Hole Image', 'fontSize', fontSize);

[labeledImage numberOfBlobs] = bwlabel(filledImage, 8); % Label
each blob so we can make measurements of it
% Get all the blob properties. Can only pass in originalImage in
version R2008a and later.
blobMeasurements = regionprops(labeledImage, grayImage, 'all');
fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid
\n');
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the mean of each blob. (R2008a has a better way where you can
pass the original image
% directly into regionprops. The way below works for all versions
including earlier versions.)
    thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of
pixels in current blob.
    meanGL = mean(grayImage(thisBlobsPixels)); % Find mean intensity
(in original image!)
meanGL2008a = blobMeasurements(k).MeanIntensity; % Mean again, but
only for version >= R2008a

blobArea = blobMeasurements(k).Area; % Get area.
blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
    fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL,
blobArea, blobPerimeter, blobCentroid);
text(blobCentroid(1), blobCentroid(2), num2str(k));
end

Subject: image processing toolbox

From: Alex

Date: 1 Jun, 2010 12:55:06

Message: 6 of 15

Thanks for your suggestion I have tried your program.
There is still a problem,I am working on hole identification in range of mm-um. for this mean even with high resolutuion cameras I could not reach a photo like yours, I mean your example is a little more advanced than IPT manual but still the picture is from coins and it is taken vertical to surface, but in my case because of some issues with machine ( measuring machine ) the working space is limited and the picture is taken with an angle of 35-45 to the surface from this view its doesn' look like a circle.

Unfortunately I could not find examples similar to this situation, the next picture shows the latest photo that I have taken and I hope it helps to understanding the situation better.

http://i49.tinypic.com/wahd8m.jpg

If you have a suggestion please share it with me.

Subject: image processing toolbox

From: ImageAnalyst

Date: 1 Jun, 2010 14:14:52

Message: 7 of 15

If you'll notice, the code I posted in the newsgroup actually DID use
the exact image that you uploaded, as opposed to the File Exchange
demo which uses the coins image . And it did a respectable job on
your image.

Now the additional picture you uploaded might possibly be able to be
solved with the same script, or some simple modifications, but I can't
tell because you didn't upload it as an individual photo - it's
combined with figures and I didn't feel like going to the work of
cropping and saving the relevant portion. Overall, this does not look
like a very tough problem to solve. The hardest part may be getting
real world units out of it since in this photo, it looks like your
image is sheared because the camera was looking at it with an oblique
angle.
-ImageAnalyst

Subject: image processing toolbox

From: Alex

Date: 3 Jun, 2010 16:00:23

Message: 8 of 15

yeah, I have checked your program, I appreciate it !

Now what can I do with the edges of the hole to reach a complete disk and later with help of the world coordinate system locate the hole position and measure it's properties with high precision, as I told earlier it's gonna use in a mm-um range so it should be very exact.

I think the problem is more serious with oblique angles.


That was my problem since beginning of this topic.

Subject: image processing toolbox

From: Alex

Date: 4 Jun, 2010 12:39:04

Message: 9 of 15

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
folder = 'K:\Haus\mlm-ad';
fullFileName = fullfile(folder, '25ztc0x.jpg');
rgbImage = imread(fullFileName);
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original RGB Image', 'fontSize', fontSize);

% Extract the red channel.
grayImage = rgbImage(:,:,1);
subplot(2, 2, 2);
imshow(grayImage, []);
title('Original Grayscale Image', 'fontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.

binaryImage = grayImage < 78;
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'fontSize', fontSize);

% Fill holes
filledImage = imfill(binaryImage, 'holes');
% Get rid of blobs smaller than 1000 pixels.
filledImage = bwareaopen(filledImage, 1000);
subplot(2, 2, 4);
imshow(filledImage, []);
title('Hole Image', 'fontSize', fontSize);
%--------------------------------------------------------------------------
% added for determining the boundary of the main hole
hold on;
boundaries = bwboundaries(filledImage);
numberOfBoundaries = size(boundaries);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
%BW=edge(grayImage,'canny')
%figure,imshow(BW);
% end of added part

[labeledImage numberOfBlobs] = bwlabel(filledImage, 8); % Label each blob so we can make measurements of it
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, grayImage, 'all');
fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid \n');
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the mean of each blob. (R2008a has a better way where you can pass the original image
% directly into regionprops. The way below works for all versions including earlier versions.)
    thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of pixels in current blob.
    meanGL = mean(grayImage(thisBlobsPixels)); % Find mean intensity (in original image!)
meanGL2008a = blobMeasurements(k).MeanIntensity; % Mean again, but only for version >= R2008a

blobArea = blobMeasurements(k).Area; % Get area.
blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
    fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL, blobArea, blobPerimeter, blobCentroid);
text(blobCentroid(1), blobCentroid(2), num2str(k));
end
total=bwarea(filledImage)

**************************************

this one is your code with a litte change , this results appears in command window:

Blob # Mean Intensity Area Perimeter Centroid
#1 69.6 3754.0 314.8 310.8 236.4

total Area form 2nd method=

  3.7696e+003

Now if I calculate the radius from the perimeter or Area , they are not equal : one is 34,56 & the other is 50,1 becasue it is not a real circle, I think of another algorithm to calculate the radius in 360° and then take the integral and finally calculate the mean value, yet I am not aware of its talorance and deviation by using this method.
for the new photo the situation is similar, only the positioning is a little though.

better ideas are warmly appreciated!
Alex

Subject: image processing toolbox

From: ImageAnalyst

Date: 4 Jun, 2010 15:11:09

Message: 10 of 15

Alex:
To get the "true" diameter, you think you'd have to know the angle
that the circle is tilted at when you're viewing it. But maybe
there's a way around it. No matter how you tilt a circle, the maximum
extent along the ellipse will be the circle diameter. So just go with
that. Detect the ellipse, and then use the MajorAxisLength as
returned by regionprops.
ImageAnalyst

Subject: image processing toolbox

From: Alex

Date: 9 Jun, 2010 09:20:23

Message: 11 of 15

Thanks for the hint ImageAnalyst.
I have another question:

persume such a case : I knew the diameter and center coordination of a circle, I want to draw a circle with this data, I prefer the results demonstrate in the previous figure that I got with imshow command :

R = blobAxislength/2; % radius
Center = [blobCentroid(1,1),blobCentroid(1,2)];
t=0:.1:2*pi;
figure,imshow(filledImage);
plot(R*sin(t),R*cos(t));
hold on
plot(Center(1),Center(2),'g.')
hold off

but the results is not satisfactory. I'd appreciate further helps.

Subject: image processing toolbox

From: ImageAnalyst

Date: 9 Jun, 2010 11:18:52

Message: 12 of 15

I don'tunderstand. That draws a circle with a dot at the center. It
won't perfectly overlap if you have an ellipse - is that the problem?
Why don't you just find the actual boundary using bwboundaries(), or
find the axes of the ellipse using the major and minor axis lengths
that regionprops finds?

Subject: image processing toolbox

From: John Brathwaite

Date: 24 Nov, 2010 01:04:04

Message: 13 of 15

Hi Image Analyst!

You seem to be very knowledgable in this field! Kudos to you!

I have some binary image files that represent joined cells that are approximately circular in shape.

I need some code to identify the circular shapes among other noise, and calculate an average diameter from the entire image.

Can you assist me with this?





ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5b6cc937-3be5-4e3c-b52b-4ad1694d4de7@y21g2000vba.googlegroups.com>...
> Not sure what your second and third pictures are all about. Why don't
> you just use standard image processing methods like this that I
> adapted from my image analysis demo at http://www.mathworks.com/matlabcentral/fileexchange/25157
>
>
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 20;
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
> folder = 'C:\Documents and Settings\username\My Documents\Temporary
> stuff';
> fullFileName = fullfile(folder, '25ztc0x.jpg');
> rgbImage = imread(fullFileName);
> subplot(2, 2, 1);
> imshow(rgbImage, []);
> title('Original RGB Image', 'fontSize', fontSize);
>
> % Extract the red channel.
> grayImage = rgbImage(:,:,1);
> subplot(2, 2, 2);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'fontSize', fontSize);
> set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
> screen.
>
> binaryImage = grayImage < 78;
> subplot(2, 2, 3);
> imshow(binaryImage, []);
> title('Binary Image', 'fontSize', fontSize);
>
> % Fill holes
> filledImage = imfill(binaryImage, 'holes');
> % Get rid of blobs smaller than 1000 pixels.
> filledImage = bwareaopen(filledImage, 1000);
> subplot(2, 2, 4);
> imshow(filledImage, []);
> title('Hole Image', 'fontSize', fontSize);
>
> [labeledImage numberOfBlobs] = bwlabel(filledImage, 8); % Label
> each blob so we can make measurements of it
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledImage, grayImage, 'all');
> fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid
> \n');
> for k = 1 : numberOfBlobs % Loop through all blobs.
> % Find the mean of each blob. (R2008a has a better way where you can
> pass the original image
> % directly into regionprops. The way below works for all versions
> including earlier versions.)
> thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of
> pixels in current blob.
> meanGL = mean(grayImage(thisBlobsPixels)); % Find mean intensity
> (in original image!)
> meanGL2008a = blobMeasurements(k).MeanIntensity; % Mean again, but
> only for version >= R2008a
>
> blobArea = blobMeasurements(k).Area; % Get area.
> blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
> blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
> fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL,
> blobArea, blobPerimeter, blobCentroid);
> text(blobCentroid(1), blobCentroid(2), num2str(k));
> end

Subject: image processing toolbox

From: ImageAnalyst

Date: 24 Nov, 2010 02:46:30

Message: 14 of 15

On Nov 23, 8:04 pm, "John Brathwaite" <clientprof...@yahoo.co.uk>
wrote:
> Hi Image Analyst!
>
> You seem to be very knowledgable  in this field! Kudos to you!
>
> I have some binary image files that represent joined cells that are approximately circular in shape.
>
> I need some code to identify the circular shapes among other noise, and calculate an average diameter from the entire image.
>
> Can you assist me with this?
------------------------------------------------------------------------
I've been doing image processing for over 30 years and have a
doctorate in the field. It's my full time job . . . and hobby! See
my profile on the FAQ for more details.
http://matlab.wikia.com/wiki/User:ImageAnalyst

Have you seen my demo:
http://www.mathworks.com/matlabcentral/fileexchange/25157
that segments coins?
You can calculate the circularity = perimeter^2 / (4*pi*area) and
values close to 1 will be circular and they are less circular the
farther they get away from 1. You can see how you can use ismember()
to filter the blobs based on circularity to keep just the circular
ones. If you have any trouble, post your image and code and we'll see
what we can do to help.

Subject: image processing toolbox

From: John Brathwaite

Date: 24 Nov, 2010 02:53:03

Message: 15 of 15

Hi Image Analyst!

You seem to be very knowledgable in this field! Kudos to you!

I have some binary image files that represent joined cells that are approximately circular in shape.

I need some code to identify the circular shapes among other noise, and calculate an average diameter from the entire image.

Can you assist me with this?





ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5b6cc937-3be5-4e3c-b52b-4ad1694d4de7@y21g2000vba.googlegroups.com>...
> Not sure what your second and third pictures are all about. Why don't
> you just use standard image processing methods like this that I
> adapted from my image analysis demo at http://www.mathworks.com/matlabcentral/fileexchange/25157
>
>
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 20;
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
> folder = 'C:\Documents and Settings\username\My Documents\Temporary
> stuff';
> fullFileName = fullfile(folder, '25ztc0x.jpg');
> rgbImage = imread(fullFileName);
> subplot(2, 2, 1);
> imshow(rgbImage, []);
> title('Original RGB Image', 'fontSize', fontSize);
>
> % Extract the red channel.
> grayImage = rgbImage(:,:,1);
> subplot(2, 2, 2);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'fontSize', fontSize);
> set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
> screen.
>
> binaryImage = grayImage < 78;
> subplot(2, 2, 3);
> imshow(binaryImage, []);
> title('Binary Image', 'fontSize', fontSize);
>
> % Fill holes
> filledImage = imfill(binaryImage, 'holes');
> % Get rid of blobs smaller than 1000 pixels.
> filledImage = bwareaopen(filledImage, 1000);
> subplot(2, 2, 4);
> imshow(filledImage, []);
> title('Hole Image', 'fontSize', fontSize);
>
> [labeledImage numberOfBlobs] = bwlabel(filledImage, 8); % Label
> each blob so we can make measurements of it
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledImage, grayImage, 'all');
> fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid
> \n');
> for k = 1 : numberOfBlobs % Loop through all blobs.
> % Find the mean of each blob. (R2008a has a better way where you can
> pass the original image
> % directly into regionprops. The way below works for all versions
> including earlier versions.)
> thisBlobsPixels = blobMeasurements(k).PixelIdxList; % Get list of
> pixels in current blob.
> meanGL = mean(grayImage(thisBlobsPixels)); % Find mean intensity
> (in original image!)
> meanGL2008a = blobMeasurements(k).MeanIntensity; % Mean again, but
> only for version >= R2008a
>
> blobArea = blobMeasurements(k).Area; % Get area.
> blobPerimeter = blobMeasurements(k).Perimeter; % Get perimeter.
> blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
> fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL,
> blobArea, blobPerimeter, blobCentroid);
> text(blobCentroid(1), blobCentroid(2), num2str(k));
> end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us