Matlab: Deleting pixels from an image (desperate)

Thread Starter

Fadel Megahed

Joined Jun 22, 2007
12
Hi,

I am working on this big project and i would like if anyone could help me generate a code that would delete all pixels under 20 from an image.
I am really stuck in the project and I am desperate for your help
Thanks a lot everyone,
 

Papabravo

Joined Feb 24, 2006
14,235
I'm not clear about your requirements. Do you want to remove the pixels from the image, or do you want to change the value of the pixels to some other value? The first would probably destroy the image. The second, depending on the meaning of less than 20, would produce something that looks like a false color image. It would also help to know what format the image is in. We are not blessed with clairvoyance or astral projection; you're just going to have to tell us, there is no other way.
 

Thread Starter

Fadel Megahed

Joined Jun 22, 2007
12
The image is a .jpg one
The function of the program is to remove the background out of the picture so that when a histogram is developed, it has the focus zones only

Thanks
 

Papabravo

Joined Feb 24, 2006
14,235
OK. Assuming you know the format of a .jpeg file a program might look like the following:
Rich (BB code):
Open filename.jpeg for input
Open Modified_filename.jpeg for output
Read and process header
Copy header to output
while(.not. EndofFile)
{
    pixel = getNextPixel() ;
    if(pixel < 20) pixel = 0 ;
    writePixel(pixel) ;
}
Close(filename.jpeg) ;
Close(Modifed_filename.jpeg) ;
 

Papabravo

Joined Feb 24, 2006
14,235
That's terrific, and you didn't even need a tutorial on the pseudo-code language I made up on the spur of the moment. I'm quitting my day job and going into language design. I may have a bright future. On second thought since retirement is just around the corner I think I'll find a couch and take a nap. Yeah...a nap, that's the ticket!
 
Top