Jump to content
  • Advertisement
Sign in to follow this  

Sobel operator and 8 bit paletted image

This topic is 2942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm having few problem applying a Sobel filter to an image that I have loaded into the NDS (I'm programming it at libnds). I have to do this in indexed color (paletted 8 bit image). Here is the code I use:
void imageToSobel(u8* bmp, u16* palette, int len, int weight, int height) {
	int i, j;
	int x, y;
	u8 p1, p2, p3, p4, p6, p7, p8, p9;
	u8 R, G, B, gray;

	for(i = 0; i < len/2; i++) {
		R = palette & 0x1F;
		G = (palette >> 5) & 0x1F;
		B = (palette >> 10) & 0x1F;
		gray = div32(30*R, 100) + div32(59*G, 100) + div32(11*B, 100);
		BG_PALETTE = RGB15(gray, gray, gray);
	}
	
	for(i = 0; i < height; i++) {
		for(j = 0; j < weight; j++) {
			p1 = bmp[(i-1)*weight+(j-1)];
			p2 = bmp[(i-1)*weight+j];
			p3 = bmp[(i-1)*weight+(j+1)];
			p4 = bmp[i*weight+(j-1)];
			p6 = bmp[i*weight+(j+1)];
			p7 = bmp[(i+1)*weight+(j-1)];
			p8 = bmp[(i+1)*weight+j];
			p9 = bmp[(i+1)*weight+(j+1)];
			
			x = (p1+(p2+p2)+p3-p7-(p8+p8)-p9);
			y = (p3+(p6+p6)+p9-p1-(p4+p4)-p7);
			BG_GFX[i*weight+j] = sqrt32((x*x) + (y*y));
		}
	}
}

The first for loop converts the image to gray scale, and do it fine. But in the next for is the problem; it's seem that doesn't do correctly... I try the same code but loading a 16 bit image and works fine, so the algorithm is correct... Could somebody help me? I don't know where is the mistake :( Thank you! PD: Sorry about my bad English.

Share this post


Link to post
Share on other sites
Advertisement
That doesn't fix the problem :/
The problem isn't it in the for which change the image into gray scale; is in the second for, which apply the sobel filter :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!