From: khalel dawod on 2 Apr 2010 07:44 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <330b61d0-0bb9-4ad4-887f-54517f907590(a)u32g2000vbc.googlegroups.com>... > K.Dawod > One way to do it. But it's not very robust and you'll have to perfect > it and make it more robust. > Be sure to join any lines broken into two by the news reader. > > > clc; % Clear the command window. > close all; % Close all figures (except those of imtool.) > clear all; % Erase all existing variables. > workspace; % Make sure the workspace panel is showing. > > % Browse for the image file. > originalFolder = pwd; > % Set up a convenient starting folder. > folder = 'C:\Documents and Settings\userName\My Documents\Temporary > images'; > if ~exist(folder, 'dir') > folder = pwd; > end > cd(folder); > baseFileName = 1; > while baseFileName ~= 0 > % Browse for the image file. > [baseFileName, folder] = uigetfile('*.*', 'Specify an image > file'); > fullImageFileName = fullfile(folder, baseFileName); > if baseFileName == 0 > % User clicked cancel. > break; > end > > % Read in standard MATLAB demo image. > rgbImage = imread(fullImageFileName); > [rows columns numberOfColorBands] = size(rgbImage); > subplot(2, 2, 1); > imshow(rgbImage); > title('Original color Image'); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > > % Get blue channel of image. > blueBand = rgbImage(:,:,3); > subplot(2, 2, 2); > imshow(blueBand); > title('Blue Band Image'); > hold on; > > % Define the ROI. > row1 = 1700; > row2 = row1 + 250; > column1 = 550; > column2 = column1 + 200; > hold on; > plot([column1 column1 column2 column2 column1], [row1 row2 row2 > row1 row1], 'r-', 'linewidth', 2); > > % Get ROI. > subImage = blueBand( row1:row2, column1:column2); > subplot(2, 2, 3); > imshow(subImage); > title('ROI'); > > % Just for fun, let's get its histogram. > [pixelCount grayLevels] = imhist(subImage); > subplot(2, 2, 4); > bar(pixelCount); title('Histogram of ROI of blue band image'); > xlim([0 grayLevels(end)]); % Scale x axis manually. > > % Calcuate the mean gray level. > meanGL = mean(subImage(:)); > if meanGL > 95 > message = sprintf('The mean gray level = %.1f\nThis bottle is > defective', meanGL); > else > message = sprintf('The mean gray level = %.1f\nThis bottle is > intact', meanGL); > end > uiwait(msgbox(message)); > end > > % Set current folder back to the original one. > cd(originalFolder); > i would like to thank you very much. this code has almost the same idea that i had in mind..... but is there anyway instead of having to segment(Crop) the image (Base of the Bottle) by using (X,Y) coordinates, as detecting the edge of the base and segmenting the base depending on the base edge, calculating the mean value of the base & upper body and then using any useful classifier to determine whether the bottle is intact or defective based on the (Base Color & Upper body color) and also, is the mean value of the "Bottle base" and "Upper Body" a good identifier that could detect a bottle as intact or defective? thank you again Khalel Dawod
From: ImageAnalyst on 2 Apr 2010 10:54 Khalel Dawod: First of all you have to decide if you're going to be serious about this and do it right, or if you're just messing around. That means, are you going to use crossed polarizers to get rid of specular reflections, a color chart for color correction, and a positioning rig to accurately mount your bottles in the same position every time? If you're serious, and capture good images, then you can just use fixed (predetermined) polygon coordinates for the places you want to look and don't need to try to find them automatically. Much like I did with the rectangular box except that you'd use poly2mask - see the demo on ROI processing in the Image Processing Toolbox help. If you're just messing around then just use what I already gave you. -ImageAnalyst
From: khalel dawod on 2 Apr 2010 13:43 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <d5ff4758-54ba-41ae-80f2-d09780023ab3(a)j1g2000vbr.googlegroups.com>... > Khalel Dawod: > First of all you have to decide if you're going to be serious about > this and do it right, or if you're just messing around. That means, > are you going to use crossed polarizers to get rid of specular > reflections, a color chart for color correction, and a positioning rig > to accurately mount your bottles in the same position every time? > > If you're serious, and capture good images, then you can just use > fixed (predetermined) polygon coordinates for the places you want to > look and don't need to try to find them automatically. Much like I > did with the rectangular box except that you'd use poly2mask - see the > demo on ROI processing in the Image Processing Toolbox help. > > If you're just messing around then just use what I already gave you. > -ImageAnalyst Yes, I'm serious about it. but for now we are about to use images taken by a digital camera (7.2MP) not station a camera on the manufacturing line to have a live feed. all pictures will have the same specs. same distance between the camera and the bottle same camera alignment we have 100 samples(50 intact and 50 defective), we are going to take all pictures and run them through an upgraded version of the code you gave us (by the way,thank you for that) to extract the needed features and store them in an array. after that we are going to write a code that would take the sample image(image to recognize) extract it's features and run it through a classifier to determine whether it's intact or defective will that be enough? and again thanks for all your help.. Khalel Dawod
From: ImageAnalyst on 2 Apr 2010 14:44 Khalel Dawod: It wouldn't be good enough or robust enough for me or my company. But if it works for you, fine. You didn't say anything about making the recommended improvements to the image capture situation (crossed polarizers, color chart, mounting rig), not to mention others I haven't mentioned already such as optical feedback to control light level, tolerance checks on the color chart, check to see that there is a bottle (of any kind) even in place, establishing tolerance or threshold to say where the bottle goes from good to bad, etc. etc. Plus I did no check for any defect in the neck of the bottle - I simply looked at the color of the bottom. You'll need to add that code, plus additional code to detect other types of defects beyond those two. Anyway, these are all things that a professional machine vision expert, or company, would put into the system. Dave Robinson, Ashish, or others could probably mention a few I left off. If you don't do all of that then you're just doing a quick and dirty feasibility study, or something like a student project rather than a professional. industrial grade solution. -ImageAnalyst
From: khalel dawod on 2 Apr 2010 15:24 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <8c2a9546-db4c-470e-a50c-90cc4f0c9ca5(a)z7g2000yqb.googlegroups.com>... > Khalel Dawod: > It wouldn't be good enough or robust enough for me or my company. But > if it works for you, fine. You didn't say anything about making the > recommended improvements to the image capture situation (crossed > polarizers, color chart, mounting rig), not to mention others I > haven't mentioned already such as optical feedback to control light > level, tolerance checks on the color chart, check to see that there is > a bottle (of any kind) even in place, establishing tolerance or > threshold to say where the bottle goes from good to bad, etc. etc. > Plus I did no check for any defect in the neck of the bottle - I > simply looked at the color of the bottom. You'll need to add that > code, plus additional code to detect other types of defects beyond > those two. Anyway, these are all things that a professional machine > vision expert, or company, would put into the system. Dave Robinson, > Ashish, or others could probably mention a few I left off. If you > don't do all of that then you're just doing a quick and dirty > feasibility study, or something like a student project rather than a > professional. industrial grade solution. > -ImageAnalyst I'm sorry if i mis-represented my self, for I'm still an undergraduate student working on this project for a pattern recognition course. But this project will have a good impact on my programming expertise using MATLAB. My assumption is, having a fully controlled environment (from lighting to the location of the camera). And as for the other defects that could be on the bottles, that will be done depending on the nature of those defects. After all that, would my project be sufficient as a good system for academic intentions? either way, i would like it if i can still be in contact with you for further inquires. Khalel Dawod
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: To display date string in data cursor Next: Not memorizing an output of a function |