Hi,
I don't think i clearly understand ur issue!. But i see an issue here. You are using(or rather reusing) the variable 'i' in the loop.
Code:
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
t=rgb1[i][j];
//printf("%d\n",t);
//delay(100);
for(i=0;i<tmp;i++) <<< Here u are using the same variable 'i' as the outer loop.
// You could use a new variable like 'inner_i' here. I guess thats what u actually intended to..
{
if(sum_hist[i][0]==t)
index=sum_hist[i][1];
}
index=index-min;
rgb1[i][j]=abs(index*255/p);
//printf("%d %d\n",t,rgb1[i][j]);
//delay(100);
}