mardi 24 février 2015

Copying part of array to a second array in C

I'm writing an image processing code to perform a median filter with a variable sized window. The greyscale image has been read into an array image1, and I'm trying to copy a window selection of the array into a second array window. This is easy for a fixed sized window (3x3 window shown) as you can just say:



window[1]=image1[m-((win_size-1)/2)][n-((win_size-1)/2)];
window[2]=image1[m][n-((win_size-1)/2)];
window[3]=image1[m+((win_size-1)/2)][n-((win_size-1)/2)];
window[4]=image1[m-((win_size-1)/2)][n];
window[5]=image1[m][n];
window[6]=image1[m+((win_size-1)/2)][n];
window[7]=image1[m-((win_size-1)/2)][n+((win_size-1)/2)];
window[8]=image1[m][n+((win_size-1)/2)];
window[9]=image1[m+((win_size=1)/2)][n+((win_size-1)/2)];


In MATLAB you can generalise this to any sized window easily by using a vector in the array call:



window = image1(m-((win_size-1)/2):m+((win_size-1)/2),n-((win_size-1)/2):n+((win_size-1)/2));


I can't work out a way to do this in C, can anyone help me with this please?


Aucun commentaire:

Enregistrer un commentaire