Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Afeza Ajirah asked . 2024-02-05

How to run this code?

Hi, i have problem on running this code due to some error. The only output is the displaying of 'original image'. Hopefully, you guys can help me fix it. Thank you so much.

 

error: Error in Wprocess (line 18) H1=rgb2gray(I2); %convert it into gray scale image

x=.01;

t=cputime;

I1=imread('lena.jpg');%read image

% I1=imread('mand.jpg');%read image

H=rgb2gray(I1); %convert it into gray scale image

J=imresize(H,[512 512]);%resize image into 512x512 image

J= double(J);

[M,N]=size(J);

figure,imshow(uint8 (J));title('Original image')

[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');

[ca,ch,cv,cd] = dwt2(J,Lo_D,Hi_D);

[ca1,ch1,cv1,cd1] = dwt2(ch,Lo_D,Hi_D);

[U,S,V] = svd(ch1);

[m,n]=size(S);

% Copy the original Singular value

Sw=S;

I2=imread('cameraman.jpg');%read Watermark image

H1=rgb2gray(I2); %convert it into gray scale image

J1=imresize(H1,[128 128]);%resize image

[a,b]=size(ch1);

W1= double(J1);

W1=imresize(W1,[a b]);% resize the 1 watermark image

[p,q]=size(W1);

%  Watermark insertion

S=S+(x*W1);

[U_w,S_w,V_w]=svd(S);

[cs1]=[U*S_w*V'];

wing = idwt2(ca1,cs1,cv1,cd1,Lo_R,Hi_R);

wing1 = idwt2(ca,wing,cv,cd,Lo_R,Hi_R);

t1=cputime;

figure,imshow(uint8(wing1)),title('Watermarked Image')

 

Image Processing and Computer Vision , Image Processing Toolbox , Image Filtering and Enhancement

Expert Answer

Prashant Kumar answered . 2025-03-23 04:40:26

It seems like you're encountering an issue with the function rgb2gray. The error message suggests that there might be something wrong with the input image I2. Here are a few steps to troubleshoot and fix this error:

  1. Check if I2 is Defined: Ensure that the variable I2 is properly defined and holds an RGB image before you call rgb2gray.

  2. Verify the Image Type: Ensure that I2 is indeed an RGB image. The rgb2gray function expects an input image of type uint8, uint16, or double with three color channels.

  3. Display and Inspect I2: Use the imshow function to display the image and inspect its properties.

Here's an example of how you can modify your code:

matlab
% Load or capture the image into variable I2
I2 = imread('your_image_file.jpg'); % or any method to load the image

% Display the original image
figure;
imshow(I2);
title('Original Image');

% Check the properties of the image
disp('Image properties:');
disp(size(I2)); % Display the size of the image
disp(class(I2)); % Display the class type of the image

% Convert the image to grayscale
H1 = rgb2gray(I2);

% Display the grayscale image
figure;
imshow(H1);
title('Grayscale Image');

Steps:

  1. Load or Capture the Image: Ensure you load the image into I2. You can replace 'your_image_file.jpg' with the actual filename or use another method to capture the image.

  2. Display the Original Image: Use imshow to display the original image and verify that it is correctly loaded.

  3. Inspect the Image Properties: Use disp to print the size and class type of the image to verify that it is an RGB image.

  4. Convert to Grayscale: Use rgb2gray to convert the RGB image to grayscale.

  5. Display the Grayscale Image: Display the converted grayscale image using imshow.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.