Is this the correct way to assign array value?

R

radishcarrot

unsigned char *m_pVolumeData;
m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];

FILE *fp = fopen(filename, "rb");
if(fp) {
fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
fclose(fp);
}

unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
psrcpixels
//is this the correct way to assign the value to another array??
pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];
}

Hi, like to check with you all.
Whether within the for loop, assigning the values are correct? I was to
assign the value of m_pVolume to pSrcPixels but it doesnt seem to
assign it correct. Pls help.
 
K

Kai-Uwe Bux

radishcarrot said:
unsigned char *m_pVolumeData;
m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];

FILE *fp = fopen(filename, "rb");
if(fp) {
fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
fclose(fp);
}

unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
psrcpixels
//is this the correct way to assign the value to another array??
pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];

Shouldn't this be:

pSrcPixels[m] = m_pVolumeData[sliceNo * m_nSizeZ + m];
}

Hi, like to check with you all.
Whether within the for loop, assigning the values are correct? I was to
assign the value of m_pVolume to pSrcPixels but it doesnt seem to
assign it correct. Pls help.


Best

Kai-Uwe Bux
 
G

george.priv

Kai-Uwe Bux said:
radishcarrot said:
unsigned char *m_pVolumeData;
m_pVolumeData = new unsigned char[m_nSizeX * m_nSizeY * m_nSizeZ];

FILE *fp = fopen(filename, "rb");
if(fp) {
fread(m_pVolumeData, 1, m_nSizeX * m_nSizeY * m_nSizeZ, fp);
fclose(fp);
}

unsigned char *pSrcPixels = new unsigned char[m_nSizeX * m_nSizeY];
for(int m=0; m<m_nSizeX * m_nSizeY; m++) { //copy the value to
psrcpixels
//is this the correct way to assign the value to another array??
pSrcPixels[m] = m_pVolumeData[sliceNo * (m_nSizeX * m_nSizeY)+m];

Shouldn't this be:

pSrcPixels[m] = m_pVolumeData[sliceNo * m_nSizeZ + m];

This is incorrect, assuming the data is sequence of frames size
m_nSizeX x m_nSizeY the original poster was correct. It may be that
your assumption about file format is wrong. Look what you see as an
image and it may give you some clues. In particular check if image is
simply distorted or it has no sense at all.

Regards,

George Privalov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top