Hi @Jenny ,
To resolve the issue with the unrecognized variable m, you first need to define m and n based on the dimensions of the input image ImJPG. The variables m and n should represent the number of rows and columns of the image, respectively. Additionally, I will ensure that the code is structured properly and includes comments for clarity. Here is the updated and complete MATLAB code:
% Load the image ImJPG = imread('your_image.jpg'); % Replace 'your_image.jpg' with your actual image file [m, n, ~] = size(ImJPG); % Get the dimensions of the image
% Initialize the output images ImJPG_Sepia = zeros(m, n, 3, 'uint8'); ImJPG_Red = zeros(m, n, 3, 'uint8'); ImJPG_Permute = zeros(m, n, 3, 'uint8');
% Sepia Transformation SepiaMatrix = [0.393 0.769 0.189; 0.349 0.686 0.168; 0.272 0.534 0.131];
for i = 1:m for j = 1:n PixelColor = reshape(double(ImJPG(i,j,:)), 3, 1); ImJPG_Sepia(i,j,:) = uint8(SepiaMatrix * PixelColor); end end
% Display the Sepia image figure; imshow(ImJPG_Sepia); title('Sepia Image');
% Red Color Transformation RedMatrix = [1 0 0; 0 0 0; 0 0 0];
for i = 1:m for j = 1:n PixelColor = reshape(double(ImJPG(i,j,:)), 3, 1); ImJPG_Red(i,j,:) = uint8(RedMatrix * PixelColor); end end
% Display the Red image figure; imshow(ImJPG_Red); title('Red Image');
% Permutation of Color Channels PermuteMatrix = [0 0 1; 0 1 0; 1 0 0];
for i = 1:m for j = 1:n PixelColor = reshape(double(ImJPG(i,j,:)), 3, 1); ImJPG_Permute(i,j,:) = uint8(PermuteMatrix * PixelColor); end end
% Display the Permuted image figure; imshow(ImJPG_Permute); title('Permuted Color Channels Image');
So, in the above modified code snippet, it begins by loading an image using imread. Make sure to replace “your_image.jpg” with the actual path to your image file. The dimensions of the image are extracted using the size function, which provides the number of rows (m) and columns (n). Then, three output images (ImJPG_Sepia, ImJPG_Red, and ImJPG_Permute) are initialized to store the results of the transformations. They are initialized as zero matrices of the same size as the input image. A sepia filter is applied using a transformation matrix. Each pixel's color is reshaped and multiplied by the sepia matrix. This transformation isolates the red channel by using a matrix that zeroes out the green and blue channels. The color channels are permuted using a specified matrix to rearrange the RGB values. Each transformed image is displayed using imshow, with appropriate titles for clarity. This code should now run without errors, and you will be able to see the results of the various color transformations applied to your image.
Please see attached.
If you have any further questions or need additional modifications, feel free to ask!