Dear all, I segmented an image using watershed and got the Label matrix. I've already found the neighbors of each region using graycomatrix. My problem is that I would like to find the location of the pixels between each pair of adjacent regions. Using bwboundaries and bwperim give all the pixel locations of each region. I just want to get the locations of the pixels situated between each adjacent regions. Thanks
MATLAB: How to find the location of the pixels between adjacent regions.
pixel location
Related Solutions
Alright, 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;%===============================================================================
% Read in good demo image.
folder = pwd;baseFileName = 'contour.jpg';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorChannels] = size(rgbImage);if numberOfColorChannels > 1 % It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = rgbImage(:, :, 2); % Take green channel.
else grayImage = rgbImage; % It's already grayscale.
end% Display the image.
subplot(2, 3, 1);imshow(grayImage, []);axis on;title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);% 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') % Threshold the image
binaryImage = grayImage > 128;% Display the image.subplot(2, 3, 2);imshow(binaryImage, []);axis on;title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');% Get rid of huge white surround
binaryImage = imclearborder(binaryImage);% Display the image.subplot(2, 3, 3);imshow(binaryImage, []);axis on;title('Border-cleared Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');% Close the image
se = strel('disk', 2, 0);binaryImage = imclose(binaryImage, se);% Display the image.subplot(2, 3, 4);imshow(binaryImage, []);axis on;title('Closed Image', 'FontSize', fontSize, 'Interpreter', 'None');% Fill holes
binaryImage = imfill(binaryImage, 'holes');% Display the image.subplot(2, 3, 5);imshow(binaryImage, []);axis on;title('Final Image', 'FontSize', fontSize, 'Interpreter', 'None');
If you have the Signal Processing Toolbox, try spectrogram() or pwelch().
Otherwise, try fft().
Best Answer