MATLAB: How to separate the whole lip image into upper and lower part using code
Image Processing Toolboxlip
Related Solutions
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');if ~hasIPT % User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?'); reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes'); if strcmpi(reply, 'No') % User said No, so exit.
return; endend% Read in a demo image.
folder = pwd % or wherever the image lives
baseFileName = 'batik22.PNG';%===============================================================================
% Read in a color reference image.
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);% Display the original color image.
subplot(2, 2, 1);imshow(rgbImage);title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);% Take the red channel
grayImage = rgbImage(:,:, 1);subplot(2, 2, 2);imshow(grayImage);axis on;title('Red Channel Image', 'FontSize', fontSize, 'Interpreter', 'None');% Threshold the image
binaryImage = grayImage < 127;subplot(2, 2, 3);imshow(binaryImage, []);title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');% Take the 8 largest blobs, then invert the image
binaryImage = ~bwareafilt(binaryImage, 8);subplot(2, 2, 4);imshow(binaryImage, []);caption = sprintf('Final Binary Image with 8 largest blobs');title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
OK, try this demo I made up specially for your attached image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 15;%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = '11.png'; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
folder = pwdfullFileName = fullfile(folder, baseFileName);%===============================================================================% Read in a demo image.
originalRGBImage = imread(fullFileName);% Display the image.
subplot(2, 3, 1);imshow(originalRGBImage, []);axis on;caption = sprintf('Original Pseudocolor Image, %s', baseFileName);title(caption, 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');drawnow;grayImage = min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(originalRGBImage);% Crop off the surrounding clutter to get the colorbar.
colorBarImage = imcrop(originalRGBImage, [1, 20, 17, rows]);b = colorBarImage(:,:,3);% Crop off the surrounding clutter to get the RGB image.
rgbImage = imcrop(originalRGBImage, [81, 1, columns-20, rows]);% Get the dimensions of the image.
% numberOfColorBands should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);% Display the image.subplot(2, 3, 2);imshow(rgbImage, []);axis on;caption = sprintf('Cropped Pseudocolor Image');title(caption, 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');drawnow;hp = impixelinfo();% Display the colorbar image.
subplot(2, 3, 3);imshow(colorBarImage, []);axis on;caption = sprintf('Cropped Colorbar Image');title(caption, 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');drawnow;% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') % Get the color map.
storedColorMap = colorBarImage(:,1,:);% Need to call squeeze to get it from a 3D matrix to a 2-D matrix.
% Also need to divide by 255 since colormap values must be between 0 and 1.
storedColorMap = double(squeeze(storedColorMap)) / 255% Need to flip up/down because the low rows are the high temperatures, not the low temperatures.
storedColorMap = flipud(storedColorMap);% Convert from an RGB image to a grayscale, indexed, thermal image.
indexedImage = rgb2ind(rgbImage, storedColorMap);% Display the thermal image.
subplot(2, 3, 4);imshow(indexedImage, []);axis on;caption = sprintf('Indexed Image (Gray Scale Image)');title(caption, 'FontSize', fontSize, 'Interpreter', 'None');drawnow;% Define the temperature at the top end of the scale
% This will probably be the high temperature.
highTemp = 28.9;% Define the temperature at the dark end of the scale
% This will probably be the low temperature.
lowTemp = 0.9;% Scale the image so that it's actual temperatures
thermalImage = lowTemp + (highTemp - lowTemp) * mat2gray(indexedImage);subplot(2, 3, 5);imshow(thermalImage, []);axis on;colorbar;title('Floating Point Thermal (Temperature) Image', 'FontSize', fontSize, 'Interpreter', 'None');hp = impixelinfo(); % Let user mouse around and see temperatures.
hp.Units = 'normalized';hp.Position = [0.45, 0.03, 0.25, 0.05];% Get the histogram of the indexed image
subplot(2, 3, 6);histogram(thermalImage, 'Normalization', 'probability');axis on;grid on;caption = sprintf('Histogram of Thermal Temperature Image');title(caption, 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Temperature', 'FontSize', fontSize, 'Interpreter', 'None');ylabel('Frequency', 'FontSize', fontSize, 'Interpreter', 'None');
Best Answer