Working on bits and bobs
I thought I’d post about a few little things that I’ve been up to, and a little review of what’s going on.
The PhD is going well - having chatted extensively with my supervisor, we’ve come up with a provisional title: “Exploring models of Human Vision in video”. This encompasses work that I’ve done already, whilst being sufficiently wide ranging to cover most of the areas of work that I might do in the future.
I’ve realised that it’s essential to divide the work into sensible chunks, with each having a hypothesis (with justification), an outline of the method that should be used to find the answer, and then the results, conclusions, and suggestions for future work. I’m now on experiment 5 or 6. Some have taken a lot longer than others, but results are starting to come forth.
Amongst the aims for the next week or so is to enter a photo competition run by UCL for images that are created during the course of research. So, I’m hoping to put something together for that.
In other news, I’ve been working on OnOneMap, which is the UK’s first property search engine map. I’ve been doing this for quite a while now, and it’s really starting to take off. Indeed, we were Radio 2’s website of the day a few weeks ago, and have had significant press coverage. I’ve been mainly working on deploying it to bigger and better servers, and ensuring they’re running optimally.
Finally, today I’ve been working on some of the code for a PhD experiment. It’s the basis for a lot of my work in the forseeable future, and so I thought it was worth doing “properly”. That is, I’m loading various images, and was having difficulty having a dynamic array of images. I wanted data[a][b].red, where a = index of the image (ie the data array would hold maybe 5 or 10 separate images), with b = i*width+j. Previously, I’d assumed that width*height<1000000, and a<10. However, I decided that malloc() was a better solution. So that anyone else out there can find out how to do this, I’ve put a simple code sample below:
#include <stdio.h>
typedef struct {
int r;
int g;
int b;
} PIXEL;
void setrgb(PIXEL *pix, int r, int g, int b);
int main(int argc, char **argv) {
PIXEL **a;
int b;
int i;
printf("Testing 2d arrays\n");
if (argc<3) {
printf("Please call this program with at least two arguments.\n");
return(1);
}
if((a = (PIXEL **)malloc((argc-1) * sizeof(PIXEL *)))==NULL) {
printf("Memory allocation failed\n");
return(1);
}
b=5;
for(i=0; i< (argc-1); i++) {
if((a[i] = (PIXEL *)malloc(5 * sizeof(PIXEL)))==NULL) {
printf("Memory allocation failed\n");
return(1);
}
}
printf("Memory allocated successfully\n");
a[0][2].r=5;
a[0][2].g=4;
a[0][2].b=3;
printf("Value at a[0][2]=%d,%d,%d\n",a[0][2].r,a[0][2].g,a[0][2].b);
setrgb(&(a[1][3]),9,8,7);
printf("Value at a[1][3]=%d,%d,%d\n",a[1][3].r,a[1][3].g,a[1][3].b);
return 0;
}
void setrgb(PIXEL *pix, int r, int g, int b) {
(*pix).r=r;
(*pix).g=g;
(*pix).b=b;
return;
}
The above should be saved as “main.c”, and compiled and run with “gcc -o test main.c && ./test 1 2 3″
November 6th, 2005 at 11:04 pm
IMHO it is better to allocate all the memory in one go rather than having to allocate argc times in the loop plus the initial pointer* allocation.