Writing array to binary file in a loop using fwrite
Ältere Kommentare anzeigen
Hi,
I am trying to write the indices of an image in a binary file uising fwrite. The indices of the entire image are written as a list of [row, col, image_number]. The fwrite and fread functions work for 1 image but for multiple images, the data seems to be distorted.
The input image and the output plot is attached. Output is supposed to be a stack of the same image but somehow they are rotated.
Thanks,
input image -

output plot -

Here is the code:
rounding_div_xy = 10;
img_in = imread('liver2d.png');
if size(img_in,3)>1
img_in = img_in(:,:,1);
end
img_in = imbinarize(img_in);
fid_pcloud = fopen('pcloud_xy.bin','w');
[rys,cxs,vs] = find(img_in>0); % -> checked that rys and cxs are 'double'
pcloud_xy_ctr = 0;
for z = 0:0.2:2
pcloud_xy_solid = [0,0,0];
for q = 1:length(rys)
pcloud_xy_ctr = pcloud_xy_ctr+1;
pcloud_xy_solid(q,:) = [cxs(q)/rounding_div_xy,rys(q)/rounding_div_xy,z];
end
fwrite(fid_pcloud,pcloud_xy_solid,'double');
end
fclose(fid_pcloud);
% reading the file ---------------------------------
fid_pcloud = fopen('pcloud_xy.bin','r');
aa = fread(fid_pcloud,[pcloud_xy_ctr,3],'double');
fclose(fid_pcloud);
pcshow(aa);
1 Kommentar
Hiten
am 13 Jan. 2021
Antworten (0)
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!