Maximiliano asked . 2020-09-30

How to isolate certain part of image?

Suppose i have a eye image, in that image i draw a circle. Now i want to isolate the circle part from the rest of image.

matlab , image processing,

Expert Answer

John Michell answered . 2024-12-20 22:27:53

All right, I have one expecially for circles that's simpler than the other one (which perhaps was ignored because its length scared you off). Don't worry - the main code in this is only one line long. Mostly it's long because of all the comments and fancy things like displaying images and giving titles to them. The main line of code is this:

maskedImage(~circleImage) = 0; % Zero image outside the circle mask.

Which you can change to

maskedImage(~circleImage) = 255; % Whiten image outside the circle mask.
if you want white instead of black.
Try this demo (also attached):
 
 
% Demo to mask an image with a circle.
% Requires the Image Processing Toolbox.
%
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
  cd(fileparts(which(mfilename)));
end
  
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Comment out whichever demo image you don not want to use.
baseFileName = 'cameraman.tif'; % Grayscale demo image.
baseFileName = 'peppers.png'; % Color demo image.

fullFileName = fullfile(folder, baseFileName);
% See if the image exists.
if ~exist(fullFileName, 'file')
  % Doesn't exist in that folder. See if it exists anywhere on the path.
  fullFileName = baseFileName;
  if ~exist(fullFileName, 'file')
    errorMessage = sprintf('Error: file %s not found', fullFileName);
    uiwait(warndlg(errorMessage));
    return;
  end
end
% Read in the image from disk.
originalImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(originalImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(originalImage, []);
% Change imshow to image() if you don't have the Image Processing Toolbox.
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize')); 
set(gcf,'name','Image Analysis Demo','numbertitle','off') 

% Initialize parameters for the circle,
% such as it's location and radius.
circleCenterX = 130; 
circleCenterY =  75; % square area 0f 500*500 
circleRadius = 50;    % big circle radius 

% Initialize an image to a logical image of the circle. 
circleImage = false(rows, columns); 
[x, y] = meshgrid(1:columns, 1:rows); 
circleImage((x - circleCenterX).^2 + (y - circleCenterY).^2 <= circleRadius.^2) = true; 
% Display it in the upper right plot. 
subplot(2,2,2); 
imshow(circleImage, []); 
% Change imshow to image() if you don't have the Image Processing Toolbox.
title('Circle Mask', 'FontSize', fontSize); 
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
drawnow;

% Mask the image with the circle.
if numberOfColorBands == 1
  maskedImage = originalImage; % Initialize with the entire image.
  maskedImage(~circleImage) = 0; % Zero image outside the circle mask.
else
  % Mask the image.
  maskedImage = bsxfun(@times, originalImage, cast(circleImage,class(originalImage)));
end

% Display it in the lower right plot. 
subplot(2, 3, 5); 
imshow(maskedImage, []); 
% Change imshow to image() if you don't have the Image Processing Toolbox.
title('Image masked with the circle.', 'FontSize', fontSize);

isolate certain


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.