Re: Extract largest continuous pixel section
Posted: 2008-07-27T14:57:12-07:00
I can think of one way to speed it up but you'll have to implement it yourself.
The program goes along each row looking for black pixels. When it finds one, the addq macro tests every coordinate to make sure that it falls within the image. If the program is rewritten so that it does a separate check for the edges of the image, testing of all the interior pixels can omit the test which ensures that the surrounding pixels are within the image.
To do this, the program could first use four loops, one to check the top row, one for each side and one for the bottom row, with each of these loops using the existing addq macro.
Then you can change the existing loop from:
to:
and then within this loop use a different macro, say "addiq", which is the same as addq except that it doesn't have the first "if" statement because we know that any black pixel we find now can't be on the edge of the image and therefore we don't have to check for edge effects.
I have no idea how much this would speed up the code, if at all, but it's worth a try.
Pete
The program goes along each row looking for black pixels. When it finds one, the addq macro tests every coordinate to make sure that it falls within the image. If the program is rewritten so that it does a separate check for the edges of the image, testing of all the interior pixels can omit the test which ensures that the surrounding pixels are within the image.
To do this, the program could first use four loops, one to check the top row, one for each side and one for the bottom row, with each of these loops using the existing addq macro.
Then you can change the existing loop from:
Code: Select all
for(j=0;j<height;j++) {
for(i=0;i<width;i++,p++) {
Code: Select all
for(j=1;j<height-1;j++) {
for(i=1;i<width-1;i++,p++) {
I have no idea how much this would speed up the code, if at all, but it's worth a try.
Pete