Assign_Read_Vis_Biosignals_Images

.m

School

Simon Fraser University *

*We aren’t endorsed by this school

Course

340

Subject

Biology

Date

Apr 3, 2024

Type

m

Pages

10

Uploaded by DeaconLion805

Report
%% CMPT340 Assignment - Reading & Visualizing Bio-signals % ============================ Goal =========================: % In this activity, you will load and visualize different data % types acquired from different modalities. % % ===================== Download Data ============================== % % First, download and unzip the BioData from Canvas: % % % The data folder contains 5 files: % % (1) emg_myopathy.txt (EMG) % % (2) bMode.mat (B-mode Ultrasound) % % (3) vol4d.mat (fMRI) % % (4) XYStripes20x20Noise_9_L_3.mat (tensor field) % % (5) clathrin_ROI_cmpt340.csv (SMLM data) clc; disp('Hamoudi Ohan Saleh Baratta') disp('SFU ID # 301540229') % %% ============================ Task 1 =============================== % (1) EMG Data % Data Description: EMG is short for electromyogram, which measures electrical activity in muscles % Requirement: % Load the data from emg_myopathy.txt and extract the two columns of values: % i) First column -- time % ii) Second column -- the amplitude of an EMG signal. close all; clear; % Load data into MATLAB: % Write your own code here: EMG = importdata('emg_myopathy.txt'); % Q1: What are the dimensions of the loaded variable (eg. 5 x 3 x 10)? % Write your own code here: sizeEMG = size(EMG); fprintf('\nVariable dimensions:\n %d x %d\n\n', sizeEMG(1), sizeEMG(2)); % How many EMG amplitude values does the signal contain? % Write your own code here: fprintf('Number of amplitudes:\n %d values\n\n', sizeEMG(1)); % Plot the amplitude vs time using the values in the two columns. % Properly label both axes. Add a suitable title to your figure. figure(1)
time = EMG(:, 1); amplitude = EMG(:, 2); plot(time, amplitude); xlabel('Time (s)'); ylabel('Amplitude (mV)'); title('EMG Signal'); % There is a period of time with a clearly reduced EMG amplitude. % Examine the previous plot, use the "Zoom In" icon on the toolbar % to close up on this region of the plot. % Visually (roughly) identify the approximate starting and ending % time for this period. % Display these values : % Write your own code here fprintf('Start:\n 16.7667\n\n'); fprintf('End:\n 16.9965\n\n'); % What are the time and amplitude values of the 100th sample of the data? % Write your own code here disp('Time_100th = '); display(EMG(100, 1)); disp('Amp_100th = '); display(EMG(100, 2)); % Plot the EMG signal from the 100th sample (in (1d)) up until the 1100th % sample. Give a title to your figure. figure(2) time_100_1100 = EMG(100:1100, 1); amplitude_100_1100 = EMG(100:1100, 2); plot(time_100_1100, amplitude_100_1100); xlabel('Time (s)'); ylabel('Amplitude (mV)'); title('EMG Signal from the 100th to 1100th sample'); %% ============================ Task 2 =============================== % (2) B-mode Ultrasound sequence % Data Description: This data represent an B-mode ultrasound video sequence (B stands for Brightness) % Requirement: Load the data in bMode.mat into MATLAB, explore the video frames and create a GIF % close all; clear; % Load data into MATLAB: % Write your own code here: load("bMode.mat"); % What are the dimensions of the loaded variable (eg. 5 x 3 x 10)? % You should output the variable dim_bMode as a vector of size 1x3.. % Write your own code here disp('bMode dimensions: '); % display your answers dim_bMode = size(bMode); % get the dimensions of bMode disp(dim_bMode); % display the dimensions
% How many frames (2D images) do we have in the video? % Write your own code here disp('Number of frames: '); % display your answer num_frames = dim_bMode(3); % get the number of frames from the third dimension disp(num_frames); % display the number of frames % What is the size (rows and columns) of each frame? % Write your own code here disp('Nb_rows:'); nb_rows = dim_bMode(1); % get the number of rows from the first dimension disp(nb_rows); % display the number of rows disp('Nb_cols:'); nb_cols = dim_bMode(2); % get the number of columns from the second dimension disp(nb_cols); % display the number of columns % Extract and display the 9-th frame of the sequence in a figure. % Apply the command that ensures that pixels are not stretched % (i.e. maintain aspect ratio of the image). Apply the command % that uses a grey colour-map to display the image. % Write your own code here figure(1) frame_9 = bMode(:, :, 9); % extract the 9-th frame of the sequence imagesc(frame_9); colormap gray; axis image; % display the frame with the grey colour-map and aspect ratio % What is the intensity value at row 30 and column 40, at frame 20? % Write your own code here disp('Intensity_(30,40,20): '); % update the display to show your answer intensity_30_40_20 = bMode(30, 40, 20); % get the intensity value at row 30, column 40, and frame 20[^23^][23] disp(intensity_30_40_20); % display the intensity value % Extract a cropped rectangular region of frame 15. % The cropped part should extend from row 10 to row 30, and from column 45 % to column 60 of the image. Display this cropped region % (also called region of interest or ROI). % Write your own code here figure(2) % update the colormap and figure title frame_15 = bMode(:, :, 15); % extract the 15-th frame of the sequence roi = frame_15(10:30, 45:60); % extract the cropped region of interest imagesc(roi); colormap gray; axis image; % display the region of interest title('Region of interest of frame 15'); % add a title to the figure % Create an animated GIF that shows the ultrasound sequence % (like a video clip). % Save this GIF image using the name US_seq.gif . % You can make use of the MATLAB code used during the lectures % Write your own code here filename = 'US_seq.gif'; % the name of the GIF file for idx = 1:num_frames % loop over all the frames frame = bMode(:, :, idx); % get the current frame [A, map] = gray2ind(frame, 256); % convert the frame to indexed image
if idx == 1 % for the first frame imwrite(A, map, filename, 'gif', 'LoopCount', Inf, 'DelayTime', 0.1); % write the frame to the GIF file with infinite loop and 0.1 second delay else % for the subsequent frames imwrite(A, map, filename, 'gif', 'WriteMode', 'append', 'DelayTime', 0.1); % append the frame to the GIF file with 0.1 second delay end end %% ============================ Task 3 =============================== % (3) Functional MRI % Data Description: This is a 3D+time f-MRI data (functional magnetic resonance image). % fMRI captures the changes in oxygenation with time (4th dimension) at every (x,y,z) location of a volume. % Requirement: Load the data in vol4d.mat into MATLAB, explore how oxygenation level changes with time % close all; clear; % Load data into MATLAB: % Write your own code here: load('vol4d.mat'); % load the data % What are the dimensions of the loaded variable (eg. 5 x 3 x 10)? % Write your own code here: disp('Size fMRI: '); % display your answer disp(size(vol4d)) % display the dimensions % Noting that the first 3 dimensions represent the spatial x, y, and z % dimensions, identify how many rows, columns, slices, and time steps % does this fMRI data have? % Write your own code here: % update the display: disp('Rows fMRI: '); % display # of rows in each slice disp(size(vol4d,1)); disp('Columns fMRI: '); % display # of columns in each slice disp(size(vol4d,2)); disp('Slices fMRI: '); % display # of slices disp(size(vol4d,3)); disp('Time fMRI: '); % display time disp(size(vol4d,4)); % Plot a curve that shows how the oxygenation level changes % with time at voxel location (x=32, y=34 , z=10). % Define axis and figure title. figure(1) % create a new figure plot(squeeze(vol4d(32,34,10,:))) % plot the oxygenation level over time at (x=32, y=34, z=10) xlabel('Time') % label the x-axis ylabel('Oxygenation level') % label the y-axis title('Oxygenation level at (x=32, y=34, z=10)') % add a title % Extract and display the slice in the X-Y plane, at slice % location z=15, of the 10th time sample.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help