Last active
December 23, 2015 07:18
-
-
Save grapeot/6599423 to your computer and use it in GitHub Desktop.
MATLAB code to rectify the RGB and depth photos directly exported from Microsoft Kinect SDK. We assume the file `imgfn` stores the binary data directly exported from `ColorImageFrame.CopyPixelDataTo()`, `dfn` stores the binary data exported from `FusionFloatImageFrame.CopyPixelDataTo()`, and `idxfn` stores the binary data exported from the `Colo…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function newImg = register(imgfn, dfn, idxfn) | |
% rectify the color image according to the depth and the alignment | |
% information from the data collection program | |
% Consult http://grapeot.me/some-technical-details-about-kinectfusion.html for more details. | |
%% read in the data | |
fp = fopen(imgfn, 'r'); | |
imgRaw = fread(fp, 'char'); | |
imgRaw = reshape(imgRaw, 4, 640, 480); | |
for i = 1: 3 | |
img(:, :, i) = reshape(imgRaw(4 - i, :, :), 640, 480)'; | |
end | |
fclose(fp); | |
fp = fopen(dfn, 'r'); | |
d = fread(fp, 'single'); | |
d = reshape(d, 640, 480)'; | |
fclose(fp); | |
fp = fopen(idxfn, 'r'); | |
idx = fread(fp, 'int'); | |
idx = reshape(idx, 2, 640, 480); | |
ii = find(idx(1, :) >= 0 & idx(2, :) >= 0); | |
fclose(fp); | |
%% do the actual alignment | |
newImg = zeros(size(img)); | |
for i = ii | |
oldy = floor(i / 640) + 1; | |
oldx = mod(i, 640) + 1; | |
y = idx(2, i) + 1; | |
x = idx(1, i) + 1; | |
newImg(oldy, oldx, :) = img(y, x, :); | |
end | |
for i = 1: 3 | |
newImg(:, :, i) = fliplr(newImg(:, :, i)) / 255; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment