필터 지우기
필터 지우기

Logical class what it is and how to import

조회 수: 12 (최근 30일)
pizzaa
pizzaa 2023년 6월 14일
댓글: pizzaa 2023년 6월 14일
What is logical class??
And 1 have 1 image how do i import it in matlab as matrix in logical and save it in.mat
Just like image above, how to import image into logical class?

채택된 답변

Ronit
Ronit 2023년 6월 14일
Logical class is a data type in Matlab that allows you to store values as either true (1) or false (0) logical values. You can use logical class to perform logical operations in Matlab.
To import an image into Matlab and save it as a logical matrix, you can follow these steps:
1. Use the imread function in Matlab to read your image into a matrix. You can use the following code:
img = imread('your_image.png'); % or 'your_image.jpg', etc.
2. Convert the matrix values to logical values using the logical function in Matlab:
img_logical = logical(img);
3. Save the resulting matrix as a .mat file using the save function:
save('your_image_logical.mat', 'img_logical');

추가 답변 (2개)

VM Sreeram
VM Sreeram 2023년 6월 14일
The documentation says that
L = logical(A) converts A into an array of logical values. Any nonzero element of A is converted to logical 1 (true) and zeros are converted to logical 0 (false).
To import an image into a logical class in MATLAB and save it as a .mat file, you can follow these steps:
1. Read the image using the imread function.
img = imread('filename.png');
2. Convert the image to grayscale. [optional if the image is already grayscale]
gray_img = rgb2gray(img);
3. Convert the grayscale image to a binary image using the imbinarize function.
binary_img = imbinarize(gray_img);
4. Convert the binary image to a logical matrix using the logical function.
logical_img = logical(binary_img);
5. Save the logical matrix as a .mat file using the save function. Choose a filename for the .mat file.
save('filename.mat', 'logical_img');

Manas
Manas 2023년 6월 14일
Hii,
For the info regarding Logical Class, you can refer to the following documentation:
For importing an image in the Logical Class, you can use this code:
% Read the image file
img = imread('image_name.png');
% Convert the image to a binary (logical) array
img_binary = logical(img);
Keep the image file and the .m file in same directory. For more info regarding this, you can refer to the following documentation: Convert numeric values to logicals - MATLAB logical - MathWorks India

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by