Tuck Wai Yip asked . 2022-03-04

How do I solve imnoise error when inserting variables that store

How do I solve imnoise error when inserting variables that store the single English alphabet and its background respectively which are logical image(which are binary image)??

Error using imnoise Expected input number 1, I, to be one of these types:

uint8, uint16, double, int16, single

Instead its type was logical.

Error in imnoise>ParseInputs (line 107) validateattributes(a, {'uint8','uint16','double','int16','single'}, {}, mfilename, ...

Error in imnoise (line 86) [a, code, classIn, classChanged, p3, p4] = ParseInputs(args{:});

Error in create_images_trial (line 34) Newforegnd_noise = imnoise(Newforegnd, 'gaussian',0, 0.01);
 
This is the error I received.How should I handle this? Because I need the background and single English alphabet to continue the process as next I will need to threshold on those separately.I attach my code below.
 
%create blank image
 w = 150;
 h = 150;
 blankImage= 255*ones(w,h,3,'uint8');
 %position of the letter in the empty cell
 position_x = (w+1)/2;
 position_y = (h+1)/2;
 % varying the font size, start from 10 to 16
 font_start = 58;
 font_end = 64; 
num_fontsA = font_start:2:font_end;
 % get the number of fonts
 numImagesA = length(num_fontsA);
 % create a cell array with number of fonts to fill in the image in next step
 A = cell(1, numImagesA);
% for loop to create letter 'A'
 % grayscale
 % store into the cell array
for i=1:numImagesA
 for font_size = num_fontsA(i)
         img= insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
         grayImage= rgb2gray(img);
         BWImage = ~grayImage;
        background = BWImage == 0;
        foreground = ~background;
        Newforegnd = foreground;
%         figure('Name','Background and Object');
         montage({Newforegnd, background});

        % Apply noise on the image
        % Apply noise on the alphabet, using 0.01 standard deviation
        Newforegnd_noise = imnoise(Newforegnd, 'gaussian',0, 0.01);
        %Apply noise on the background, using 0.01 standard deviation
        background_noise = imnoise(background, 'gaussian',0, 0.01);

        %Format figure name into string with font size automatically
        %iterates using assigned variable font_size
        % %d is decimal notation for the font size variable as it is in
        % whole number
        f = figure('Name','Foreground & background image before & after adding noise','NumberTitle','off');
        p = uipanel('Parent',f,'BorderType','none');
        p.Title = sprintf('For alphabet with font size of %d ',font_size);
        p.TitlePosition = 'centertop';

        %divide the figure into subplot
        %which above is foreground of the alphabet
        %while the background of alphabet at below
        subplot(2,2,1,'Parent',p);
        imshow(Newforegnd);
        h1 = gca;
        h1.Visible = 'on';
        title("Foreground image of the single alphabet");

        subplot(2,2,2,'Parent',p);
        imshow(Newforegnd_noise);
        h2 = gca;
        h2.Visible = 'on';
        title("Image of the single alphabet(after adding noise) ");

        subplot(2,2,3,'Parent',p); 
        imshow(background);
        h3 = gca;
        h3.Visible = 'on';
        title("Background of the single alphabet");

        subplot(2,2,4,'Parent',p);
        imshow(background_noise);
        h4 = gca;
        h4.Visible = 'on';
        title("Background of the single alphabet(after adding noise)");

Is that anyone could guide me what to do next for putting the gaussian noise ,the image now is in logical form,it can be grayscale it is made into binary because I separate the alphabet and its background into different variable?Thank you.

image processing , MATLAB , Image Processing Toolbox

Expert Answer

Prashant Kumar answered . 2024-12-21 19:31:55

Newforegnd & background are BW image which is class logical and imnoise does not support.
 
You may change it to class double or uint8 as follows as an example.
 
Newforegnd_noise = imnoise(double(Newforegnd), 'gaussian',0, 0.01);
        %Apply noise on the background, using 0.01 standard deviation
background_noise = imnoise(double(background), 'gaussian',0, 0.01);
%
%
%
Newforegnd_noise = imnoise(uint8(Newforegnd*255), 'gaussian',0, 0.01);
        %Apply noise on the background, using 0.01 standard deviation
background_noise = imnoise(uint8(background*255), 'gaussian',0, 0.01);

 


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.