read specific values and ignore them using fread

Hello!
So I'm trying to find a way to read from a matrix of size 1x2000 the values that are assigned in positions 750 to 834 using the fread command.
Basically I open the given file that I want to read,using the command:
fid=fopen('Alien_Message');
im_1=fread(fid,251,'uint8'); %read the main header of the file and the line header and toss them away
im_2=fread(fid,[],'uint8'); %This is the part where I want to read the 750 to 834 bitstream and toss them away
Any idea on how can I manage this?

 Accepted Answer

yes,sir,may be use loop to make it,but the result should be check,such as
fid=fopen('Alien_Message');
im_1=fread(fid,251,'uint8'); %read the main header of the file and the line header and toss them away
im_2 = [];
for i = 1 : 834
tmp = fread(fid,1,'uint8');
if i >= 750
im_2 = [im_2 tmp];
end
end

3 Comments

In the same manner, when I have 4 variables (say im_1 im_2 im_3 and im_4) and I want to exclude them from the bitstream that represents an image, how can I calculate in the end the final dimension of the image by excluding those data?
Just to clarify, my four variable are of size1x86 double, the im_raw is used to identify the dimensions of the final image and then used to represent it. I thought of making a final matrix that creates an 86x86 matrix that can be excluded using the fread command but I don't know if my way of thinking is logical.
Please help me. I'm desperate!
fid=fopen("Alien_Message"); %Here we're reading the image from the local folder
data=fread(fid,[1 2000],'uint8');
fclose(fid);
figure;
plot(data(1:2000));
title('Πρώτα 2000 στοιχεία ανεπεξέργαστων δεδομένων');
%Χρησιμοποιώντας την εντολή imfinfo('Alien_Message'),εντοπίζονται τα
%στοιχεία της εικόνας. Από εκεί το line_length υπολογίζεται ότι είναι
%307200
line_length=578; %the length of the line_length
len_line_header=53; %the length of the line header
%We're reopening the file to read the data beyond the main header of the
%image
fid=fopen('Alien_Message');
main_header=[]; %Δημιουργία κενού πίνακα main_header
for e=1:170 %Χρήση εντολής επανάληψης for για το προσαρμοσμένο εύρος τιμών που λαμβάνει ο header με βάση την απεικόνιση
tmpmain=fread(fid,1,'uint8'); %Αρχικοποίηση μιας μεταβλητής ώστε να διαβάζει την fid, να κρατά σταθερή την σειρά και να διαβάζει μεταβλητή τύπου uint8
if e<=168
main_header=[main_header tmpmain]; %Εντολή if ώστε να δίνεται μόνο μέχρι ένα συγκεκριμένο όριο τιμών στην μεταβλητή του main_header και να αποδίδεται στον αρχικά κενό πίνακα η σειρά των στοιχείων που ορίζεται από τις επαναλήψεις
end
end
%Γίνεται ανάγνωση του άγνωστου μηνύματος μετά την αφαίρεση του main header
im_raw=[];
for r=170:1912
tmpraw=fread(fid,1,'uint8');
if r>=170
im_raw=[im_raw tmpraw];
end
end
fclose(fid);
num_lines=2;
fid=fopen('Alien_Message');
im_1=[];
for n=1:252
tmp1=fread(fid,1,'uint8');
if n>=167
im_1=[im_1 tmp1];
end
end
im_2=[];
for i=252:834
tmp2=fread(fid,1,'uint8');
if i>=749
im_2=[im_2 tmp2];
end
end
im_3=[];
for j=834:1415
tmp3=fread(fid,1,'uint8');
if j>=1330
im_3=[im_3 tmp3];
end
end
im_4=[];
for m=1415:1997
tmp4=fread(fid,1,'uint8');
if m>=1912
im_4=[im_4 tmp4];
end
end
im_finale= im_1.*(im_2)'.*(im_3)'.*(im_4)';
fclose(fid);
im=im_raw(.....) %here are supposed to be entered the values of the final matrix for the image
im_final=im2uint8(im);
figure;
imshow(im_final);
I can't load the file to the forum because the website does not give me the permission. Yet, this is the graph that I use to recompose the
if i run the program giving im_raw the dimension that I see from workspace (1743,1) it returns me this error:
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in den_katalabainw_xristo (line 98)
im=im_raw(1743,1); %here are supposed to be entered the values of the final matrix for the image

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!