![]() |
|
|||||||
| Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc. |
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
All right, so i've developed my algorithm for spectral comparison in MATLAB. I read the images into matlab and convert them to grayscale. Now what i want to do have the program scan the images for black pixels. so basically
numbkpixels = 0; while (in picture range) if pixel = black numbkpixels = numbxpixels + 1 else go to next pixel return numbkpixels any ideas? Last edited by Tek_Knowledge; 04-27-2008 at 04:45 PM. |
|
#2
|
||||
|
||||
|
If at all possible you need to avoid using loops in Matlab, particularly for large image sets. Can I ask what function (or argument from your image read function) you using to obtain the grayscale image? The reason I ask is that there might be a vectorised option built into Matlab, but this will depend on the functions used.
Dave
__________________
All About Circuits "If I have seen a little further it is by standing on the shoulders of Giants" - Sir Isaac Newton
|
|
#3
|
|||
|
|||
|
Quote:
function rgb2gray |
|
#4
|
||||
|
||||
|
I cannot see a vectorisation option in Matlab for the output of the rgb2gray function so we are looking at loops.
Am I correct to assume the grayscale image is of datatype uint8? (You will be able to see this from the Matlab workspace). The important point is that datatype is unsigned, therefore the pure-black pixels will be of value 0. What you are asking for is a function that will deduce the number of black pixels. If so, then the following loops will work (be sure to debug the syntax - I am writing this without Matlab to hand): Code:
% I is your image from imread or other image read function J = rgb2gray(I); numblkpxl = 0; for n = 1:(size(J,2))Select Allfor m = 1:(size(J,1))endif isequal(0,J(m,n))endnumblkpxl = numblkpxl + 1;end Dave
__________________
All About Circuits "If I have seen a little further it is by standing on the shoulders of Giants" - Sir Isaac Newton
|
|
| Tags |
| code, comparison, image, matlab |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Matlab code needed!! | zico | Programmer's Corner | 6 | 01-29-2013 03:10 PM |
| Matlab R2007 stuck initializing | Dave | Programmer's Corner | 5 | 04-28-2009 10:20 PM |
| Matlab Source Code (discrete wavelet transform) | ninjutsu | Programmer's Corner | 3 | 03-14-2009 06:59 PM |
| Useful Matlab Information | Dave | Programmer's Corner | 7 | 11-09-2008 05:51 AM |
| Installing Matlab Student on Suse Linux 10 | Dave | Programmer's Corner | 0 | 01-22-2006 01:07 PM |
| Thread Tools | |
| Display Modes | |
|
|