C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 4th, 2008, 11:45 AM
bytefx bytefx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: UK
Posts: 116 bytefx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 52 sec
Reputation Power: 10
Unhappy Set up a float array and populate

can someone advise on the putting this array togther.

basically i created a float array like so

Code:
float Hist_r[2000] = {0.0}; (initialise all bins with 0)


PHP Code:
/* Sets variables. */
        
data image->data;
        
image->width;
        
image->height;

        
// normalisation factor 
        
float norm_f / (h);
        
float x,y,za,b,c;

for ( 
0hj++ )
        {
            for ( 
iiwi++)
            {

                
/* RED */
                // dirac unit impulse function
                
=    (((data[(w*(j))])) - ((data[((i-1) + w*(j-1))])));
                
//normalise a < 1, 1/w*h
                
= (norm_f a);
                
Hist_r[a]++;
    }



I would like to create an array or histogram of floating values. is there an optimised way to do this

Reply With Quote
  #2  
Old February 4th, 2008, 12:55 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
First of all, I don't know how your "image" is implemented, but it sure looks like you're walking off the end of your array in that for loop. (Do you know what's in data[(-1) + w*(-1)]?)

Secondly, if your array Hist_r is counting occurrences of things, then its type should probably be int or unsigned int rather than float (unless you have a good reason for it to be float).

Thirdly, you need to normalize your index to the range [0, 2000), not [0, 1), since your array has 2000 elements. You should also make sure that the index you're using is not less than 0 or greater than or equal to 2000.

Reply With Quote
  #3  
Old February 4th, 2008, 04:04 PM
bytefx bytefx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: UK
Posts: 116 bytefx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 52 sec
Reputation Power: 10
Quote:
Originally Posted by Lux Perpetua
First of all, I don't know how your "image" is implemented, but it sure looks like you're walking off the end of your array in that for loop. (Do you know what's in data[(-1) + w*(-1)]?)

Secondly, if your array Hist_r is counting occurrences of things, then its type should probably be int or unsigned int rather than float (unless you have a good reason for it to be float).

Thirdly, you need to normalize your index to the range [0, 2000), not [0, 1), since your array has 2000 elements. You should also make sure that the index you're using is not less than 0 or greater than or equal to 2000.


firstly : Ok, well spotted. no i don't know what's beyond data[(-1) + w*(-1)]?) its a bad attempt at trying to decipher an equation (1) for histogram function in the pdf (see attachment). except you can advise on what dirac or unit impulse function for the pixel is (eqn 1)? and what the code would look like

secondly: Yes... i am counting occurances... and its not a simple histogram as each bin value or element will be normalised by number of counts for both loops... in this case (resolution = width * height). its more of a probality density function

thirdly: 2000 equates to number of bins for the histogram.

i appreciate your response, but i just don't understand how to translate this equations (1,2 and 3) into c /c++ code
Attached Files
File Type: pdf vertan-embedding_fuzzy_histograms.pdf (71.7 KB, 154 views)

Reply With Quote
  #4  
Old February 4th, 2008, 05:35 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4850
Pardon me for saying so, but you should ask the question you want an answer to. Seems far-fetched, I know.
__________________
Write no code whose complexity leaves you wondering what the hell you did.
Politically Incorrect DaWei on Pointers Grumpy on Exceptions

Reply With Quote
  #5  
Old February 5th, 2008, 03:52 AM
bytefx bytefx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: UK
Posts: 116 bytefx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 52 sec
Reputation Power: 10
Unhappy

Quote:
Pardon me for saying so, but you should ask the question you want an answer to. Seems far-fetched, I know.


ok, here's my question ...

how do you code a dirac impulse function of a pixel colour value in C.

Normal way i'm used to creating a histogram or occurances of red i.e. c = f(i,j) where i,j are vector or set of pixel in an image

image loaded and data is the container, so i have histogram of r,g,b values ..
expressed as
H(i,j)rgb = sum(i).sum(j) [f(i,j)]
Code:
unsigned char * data = (unsigned char*) malloc (3*w*h..blah)
w = 100
h =  75
hist_r[256] = {0};
hist_g[256] = {0};
hist_b[256] = {0};

for (int j = 0; j < h; j++){
 for (int i = 0; i < w; i++){

 unsigned int r= data[ ((j)*w) + i)];
 unsigned int g= data[ ((j)*w) + i)+1];
 unsigned int b= data[ ((j)*w) + i)+2];

hist_r [r]++;
hist_g[g]++;
hist_b[b]++;

  }
}


now the difference is that i need to get the probablity density function for the r,g,b vlaues of the image such that
the bin values sum to 1.
H(i,j)rgb = (1/w*h) sum(i).sum(j) dirac[f(i,j)]
where d(x) = u(x) - u(x-1). (d(n) = unit impulse function). hence the previous code...with array of 2000 elements containing floats.

Code:
/* Sets variables. */ 
       float hist_r[2000] = {0.0};
        w = 100; 
        h = 75; 

        // normalisation factor  
        float norm_f = 1 / (w * h); 
        float r,g,b; 

for ( j = 0; j < h; j++ ) 
        { 
            for ( i= 0 ; i< w; i++) 
            { 

                /* RED */ 
                // dirac unit impulse function 
               r =   abs (((data[(i + w*(j))])) - ((data[((i-1) + w*(j-1))]))); 
                //normalise a < 1, 1/w*h 
                a = (norm_f * a); 
                Hist_r[a]++; <--- i can't do this because the element needs to be an integer but i need to create unit impulses of floats.. probability the colour occurrs 
    } 
}  

The Dirac delta function d(x) takes the value zero everywhere except when x=0. so i need to populate the histogram with the occurrences of each colour c in the image.
and the finally redefine each bin value according to its ratio with the largest bin value.

Reply With Quote
  #6  
Old February 5th, 2008, 04:53 AM
etienne141's Avatar
etienne141 etienne141 is offline
Paris est magique!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: France!
Posts: 370 etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 21 h 48 m 52 sec
Reputation Power: 95
Send a message via ICQ to etienne141 Send a message via MSN to etienne141
Something I don't get:

You store RGB values in an array. I assume that you use 0..255 values for each color. A commonly used way to store RGB values would be to use, say an int, the first byte being red, then blue, then green, the 4th remains open for transparency, luminance, whatever...

That gives you:
Code:
int aRGB[ w * h];

To index a value in your array:
int col = aRGB[ j*w + i];

// Then address the bytes to get a particular color.
char R = *((char *) &col);
char G = *(((char *) &col) + 1);
char B = *(((char *) &col) + 2);


Or (as it seems you are trying to do):

Code:
const int ELEM_LENGTH = sizeof(int);
char aRBG[ w * h * ELEM_LENGTH];

//To index R,G, B values in your array:
aRGB[ (j * ELEM_LENGTH) * w + (i * ELEM_LENGTH)];
aRGB[ (j * ELEM_LENGTH) * w + (i * ELEM_LENGTH) + 1];
aRGB[ (j * ELEM_LENGTH) * w + (i * ELEM_LENGTH) + 2];


Yet, a cleaner way would be to:

Code:
typedef struct
{
    char R;
    char G;
    char B;
} my_color;

my_color aRGB[ w * h];

// index:
aRBG[ j*w + i].R;
aRBG[ j*w + i].G;
aRBG[ j*w + i].B;


The last solution allows you to change the type of R,G,B components, if you want ot give more precision to a 'bigger' type.
__________________
etienne:~ > %blow
fg: %blow: no such job


There are 10 kind of people:
- those who know binary
- those who don't.

Reply With Quote
  #7  
Old February 5th, 2008, 05:17 AM
etienne141's Avatar
etienne141 etienne141 is offline
Paris est magique!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: France!
Posts: 370 etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level)etienne141 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 21 h 48 m 52 sec
Reputation Power: 95
Send a message via ICQ to etienne141 Send a message via MSN to etienne141
I am not sure I understand what you are want to achieve. Yet, what do you say from the following?


Code:

#include <math.h>

// You want floats? Let's use floats.
typedef struct
{
float R;
float G;
float B;
} my_color;
// Or is one item' color stored over _one_ float? Needs to be precised!


const int w = 100; 
const int h = 75; 


// the red part of the data to normalise. Right?
float hist_r[ w * h] = {0.0};
float hist_g[ w * h] = {0.0};
float hist_b[ w * h] = {0.0};

my_color data[ w * h];
float r, g, b;
int iR, iG, iB;

// normalisation factor  
float norm_f = 1 / (w * h); 


for( j = 0; j < h; j++ ) 
{ 
    for( i= 0 ; i< w; i++) 
    { 

        /* RED component*/ 
        
        // dirac unit impulse function 
        // don't get what you do here. How is that a dirac? With what parameter?
           r =   abs (data[(i + w*(j))].R - data[(i-1) + w*(j-1)].R);
           g =   abs (data[(i + w*(j))].R - data[(i-1) + w*(j-1)].R);
           b =   abs (data[(i + w*(j))].R - data[(i-1) + w*(j-1)].R);
           
        // normalise a < 1, 1/w*h
        // round it to the closest int.
        // you better have r, g, b distributed in [0,w*h]
        iR = floor( norm_f * r); 
        iG = floor( norm_f * g); 
        iB = floor( norm_f * b); 
        
        hist_r[ iR]++; 
        hist_g[ iG]++;  
        hist_b[ iB]++; 
    } 
} 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Set up a float array and populate

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap