I want to get binary data from a bin file.

1 个评论
回答(2 个)
Hi @大地 ,
After going through your comments, in order to retrieve binary data from a LabVIEW-generated bin file in MATLAB and convert it into an image, you can follow these steps:
1. Read the Binary File: Use the fopen and fread functions to read the binary data from the bin file.
2. Reshape the Data: Since the image is 256x256 pixels, reshape the data into a 2D matrix.
3. Convert to Image: Use the imshow function to display the image.
Here is a sample code snippet to achieve this:
% Specify the path to the bin file filePath = 'path_to_your_file.bin';
% Open the binary file fileID = fopen(filePath, 'r');
% Read the binary data data = fread(fileID, [256, 256], 'uint8'); % Adjust data type as necessary
% Close the file fclose(fileID);
% Display the image imshow(data, []); title('Image from Binary Data');
% Optionally, read and display the BMP file for comparison bmpImage = imread('path_to_your_file.bmp'); figure; imshow(bmpImage); title('Original BMP Image');
This code will help you visualize the binary data as an image and allow you to compare it with the BMP file to confirm their similarity. Ensure that the data type in fread matches the format used in LabVIEW.
Hope this helps.
11 个评论
Hi @大地,
Please see attached. I did comparison check and both images are not equal. I did find out that there is array size are not compatible and images are different dimensions.


8 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!