I've got a problem with my project. My program load bytes to a buffer(it's 1D bytes array), when I want to set the offset of my data I create a 2D int[]
array, then i convert this to the 1D int
array, the last step is to convert 1D int array to 1D bytes array. But the results arent the same as in my matlab function. I put my code below, hope someone will give me some tips.
public byte[] sekwencja(String nazwa) throws FileNotFoundException, IOException{
InputStream is = null;
DataInputStream dis = null;
is = new FileInputStream(nazwa);
dis = new DataInputStream(is);
int length = dis.available();
byte[] buf = new byte[length];
dis.readFully(buf);
int l_klatek = ((length-158864)/158864)+1;
int width = 320;
int height = 240;
int C1=21764040;
double C2=3033.3;
double C3=134.06;
int z = 0;
int[] oneDArray = new int[width*height];
byte[] rawPixels2 = new byte[oneDArray.length];
int [][] pixels = new int[width][height];
int offset = 1360;
int wart;
for(int x = 0; x<320; x++){
for (int y = 0; y<240;y++){
//int wart = buf[offset & 0xFF] ;
//int wart = buf[offset];
wart =(buf[offset& 0xFF + 1] )*256 + buf[offset& 0xFF ] ;
pixels[x][y]= (int) (C2/log(C3+C1/(wart+1))-273.15);
//rawPixels2[z++] = (byte) (0xFF & oneDArray[x]);
offset = offset+2;
}
}
for(int i = 0; i < width; i ++)
{
for(int s = 0; s <height; s ++)
{
oneDArray[(i * height) + s] = pixels[i][s];
}
}
ByteBuffer byteBuffer = ByteBuffer.allocate(oneDArray.length * 4);
IntBuffer intBuffer = byteBuffer.asIntBuffer();
intBuffer.put(oneDArray);
byte[] array = byteBuffer.array();
return array;
Matlab fun
function macierz_2D = pokaz_img_nr(nazwa_pliku,nr_klatki)
%wyswietla klatke z sekwencji
%close all
fid = fopen(nazwa_pliku,'r');
[sekwencja,l_bajtow] = fread(fid, inf, 'uchar');
l_klatek=(l_bajtow-158864)/158864 +1;
%stale kalibracyjne kamery
C1=21764040;
C2=3033.3;
C3=134.06;
clk=clock;
offset=(nr_klatki-1).*158864 + 1373;
%offset=1360;
%if (nr_klatki>1)
% offset=158136+(nr_klatki-1)*569+(nr_klatki-2)*(320*240*2+3839);
%end
for nr_y=1:240
for nr_x=1:320
wartosc=sekwencja(offset);
wartosc= (sekwencja(offset))+(sekwencja(offset+1))*256;
%macierz_2D(nr_y,nr_x) = wartosc;
macierz_2D(nr_y,nr_x)=C2/log(C3+C1/wartosc)-273.15;
offset=offset+2;
end
end
liczba_minut = etime(clock,clk)/60
clear sekwencja
%colormap(hot)
%colormap((jet))
im = imagesc(macierz_2D(:,:));
imagesc(macierz_2D(:,:));
saveas(gcf,'im.png');
grid on;
%caxis([9000 12500]);
axis([1 320 1 240]);
axis image;
colorbar('horiz');