0% found this document useful (0 votes)
8 views6 pages

Lab Assignment 1 Aim

The lab assignment aims to explore various matrix filling patterns (row-wise, column-wise, diagonal-wise) using MATLAB to understand their organization and efficiency. The experiment involves initializing a 1024x1024 matrix and filling it with values from 0 to 255 in specified patterns, followed by operations like addition, multiplication, and image processing. Observations indicate that each filling pattern creates distinct structures, providing insights for optimizing computational tasks and algorithm design.

Uploaded by

hackerishere1001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Lab Assignment 1 Aim

The lab assignment aims to explore various matrix filling patterns (row-wise, column-wise, diagonal-wise) using MATLAB to understand their organization and efficiency. The experiment involves initializing a 1024x1024 matrix and filling it with values from 0 to 255 in specified patterns, followed by operations like addition, multiplication, and image processing. Observations indicate that each filling pattern creates distinct structures, providing insights for optimizing computational tasks and algorithm design.

Uploaded by

hackerishere1001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB ASSIGNMENT-1

Aim: The aim of this experiment is to explore and analyze different


matrix filling patterns, including row-wise, column-wise, and
diagonal-wise filling, to understand their organization, efficiency, and
applicability in various computational tasks.

Software Used: MATLAB


Theory:
Initialize a 1024x1024 matrix with zeros.
For each value from 0 to 255:
For row-wise filling: Identify the corresponding block of 4 rows and
fill it with the current value.
For column-wise filling: Identify the corresponding block of 4
columns and fill it with the current value.
For diagonal-wise filling: Identify the corresponding diagonal block
of 4x4 and fill it with the current value.
Addition and Subtraction:

These operations are not directly related to the experiment's filling


patterns but are fundamental for combining matrices or adjusting their
values after filling.
Multiplication:

Matrix multiplication can be employed to apply transformations or


operations to matrices filled using the described patterns. For
instance, multiplying a matrix filled row-wise by another matrix can
help apply row-wise transformations.
Transpose:

Transposing a matrix can change its orientation, flipping rows into


columns and vice versa. This operation might be useful when
manipulating matrices filled in specific patterns to match the desired
orientation for further computations.
Inverse:

The concept of the matrix inverse is relevant for certain operations


such as undoing transformations or solving systems of equations. It
may not be directly applicable to the experiment's filling patterns but
could be useful in subsequent analyses.
Determinant:

The determinant of a matrix can provide information about its


properties, such as its invertibility. While not directly related to the
filling patterns, understanding determinants can aid in analyzing the
characteristics of matrices produced by the experiment.
Eigenvalues and Eigenvectors:

Eigenvalues and eigenvectors describe the behavior of linear


transformations and could be relevant in analyzing the matrices
generated by the experiment, especially for diagonal-wise filled
matrices where eigenvalues may play a significant role.
Program:
%% row wise

% Initialize the matrix with zeros


matrix = zeros(1024, 1024);

% Fill the matrix with values ranging from 0 to 255 in blocks of 4 rows
for i = 0:255
startRow = i * 4 + 1;
endRow = (i + 1) * 4;
matrix(startRow:endRow, :) = i;
end
% Display the entire matrix
disp(matrix);

%% column wise

% Initialize the matrix with zeros


matrix = zeros(1024, 1024);

% Fill the matrix with values ranging from 0 to 255 in blocks of 4 columns
for i = 0:255
startCol = i * 4 + 1;
endCol = (i + 1) * 4;
matrix(:, startCol:endCol) = i;
end

% Display the entire matrix


disp(matrix);

%% diagonal wise

% Initialize the matrix with zeros


matrix = zeros(1024, 1024);

% Fill the matrix diagonal with values ranging from 0 to 255


for i = 0:255
matrix(i*4 + 1:(i+1)*4, i*4 + 1:(i+1)*4) = i;
end

% Display the entire matrix


disp(matrix)

% Create a random matrix


matrix = randi([0, 225], 1024, 1024);

% Convert matrix to image


image = mat2gray(matrix);

% Display the original image


figure;
subplot(2, 2, 1);
imshow(image);
title('Original Image');

% Extract a region at pixel (256,300)


extractedPixel = image(256, 300);

% Display the extracted pixel value


subplot(2, 2, 2);
imshow(image);
hold on;
plot(300, 256, 'r+', 'MarkerSize', 10);
title(['Extracted Pixel Value: ' num2str(extractedPixel)]);

% Extract pixels from range (100,100) to (500,500)


subImage = image(100:500, 100:500);
% Display the extracted sub-image
subplot(2, 2, 3);
imshow(subImage);
title('Extracted Sub-Image (100:500, 100:500)');

% Save the extracted sub-image to a file


imwrite(subImage, 'extracted_subimage.png');

% Display the saved image


subplot(2, 2, 4);
imshow('extracted_subimage.png');
title('Saved Extracted Sub-Image');

% Adjust the layout for better visualization


sgtitle('Image Processing Operations');

% Initialize the matrix with zeros


matrix = zeros(1024, 1024);

% Fill the matrix with values ranging from 0 to 255 in blocks of 4 rows
for i = 0:255
startRow = i * 4 + 1;
endRow = (i + 1) * 4;
matrix(startRow:endRow, :) = i;
end

% Display a portion of the matrix to check the values


disp(matrix(1:8, 1:16));

% Initialize matrices with zeros


matrixRow = zeros(1024, 1024);
matrixCol = zeros(1024, 1024);
matrixDiag = zeros(1024, 1024);

% Fill matrices row-wise, column-wise, and diagonal-wise


for i = 0:255
% Row-wise
matrixRow(i*4 + 1:(i+1)*4, :) = i;

% Column-wise
matrixCol(:, i*4 + 1:(i+1)*4) = i;

% Diagonal-wise
matrixDiag(i*4 + 1:(i+1)*4, i*4 + 1:(i+1)*4) = i;
end

% Combine matrices to create a new matrix


matrixCombined = matrixRow + matrixCol + matrixDiag;

% Convert the matrix into a color image


colorImage = ind2rgb(mat2gray(matrixCombined), jet(256));

% Display the color image


imshow(colorImage);
Output:

Observations:
Each filling pattern results in a structured matrix arrangement:
Row-wise: Blocks of 4 rows with increasing values from 0 to 255.
Column-wise: Blocks of 4 columns with increasing values from 0 to
255.
Diagonal-wise: Diagonal blocks of 4x4 with increasing values from 0
to 255.
The row-wise and column-wise patterns exhibit clear row and column
structures, respectively, whereas the diagonal-wise pattern forms
diagonal structures across the matrix.

Conclusion:
In conclusion, by examining these different matrix filling patterns
within a single experiment, we gain insights into their respective
characteristics, functionalities, and potential applications,
empowering informed decision-making in computational tasks and
algorithm design. Understanding these patterns enables the selection
of the most suitable arrangement for specific computational tasks,
optimizing performance and resource utilization

You might also like