If you make some assumptions about the image, there is a way to find the height and width.
1. Image is all grayscale uint8
2. Image has no header, just pure pixel info
3. Image isn't all stripes going up-down or left-right
If these are met, your can get the width by finding the first peak in the self correlation:
[filename, pathname] = uigetfile({'*.raw'},'Pick an Image ');
fid=fopen([pathname filename],'r');
Data=fread(fid,inf,'uint8=>uint8');
fclose(fid);
fftData = fft(Data);
selfcorr = ifft(fftData .*conj(fftData ));
selfcorr = selfcorr -mean(selfcorr);
peaks = selfcorr([2:end 1]) - selfcorr;
peaks = peaks([2:end 1]) - peaks;
ispeak = peaks < peaks([2:end 1]) & peaks < peaks([end 1:end-1]) & peaks < peaks(end)/10;
k = numel(Data);
w = find(ispeak,1);
h = k / w;
IMG = reshape(Data,[w h]);
imshow(IMG);
These assumptions don't apply to all *.raw files, as it is a jungle of formats, most including a header. I just deduced these assupmtions from the code you provided. If you have any kind of header, the code won't work.
Edit: two typos in that code, hope it works now. Data is indeed the image data. k should be numel(Data) or length(Data)
0 Comments
Sign in to comment.