Borrar filtros
Borrar filtros

Post-Image Processing Question

2 visualizaciones (últimos 30 días)
Inderdeep Grewal
Inderdeep Grewal el 30 de Abr. de 2018
Comentada: Inderdeep Grewal el 2 de Mayo de 2018
Background - I am using a direct image correlation (DIC) program called NCORR to create strain fields. My goal is to try and automate the output images post processing. (reference image attached)
After turning the strain fields into logical binary (black and white) using the command "im2bw", I want to be able to mark the image such that if I define a given minimum distance across the white area must be, a line is drawn down the center of that minimum distance through.
How would I be able to go about doing such an action and potentially running it multiple times over the span of multiple images?

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Abr. de 2018
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;
%===============================================================================
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.jpg');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
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;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
drawnow;
% Threshold the image.
binaryImage = grayImage > 50; % Hgh enough to get rid of bad JPEG artifacts. Never use JPEG for image analysis!
% Get rid of blobs rouching the border, like that white frame.
binaryImage = imclearborder(binaryImage);
% Take largest remaining blob.
binaryImage = bwareafilt(binaryImage, 1);
% Display the image.
subplot(1, 2, 2);
imshow(binaryImage, []);
title('Binary Image with line down it', 'FontSize', fontSize, 'Interpreter', 'None');
% Go down image finding first and last points
hold on;
minRequiredDistance = 10; % Whatever....
x = NaN(rows, 1);
y = NaN(rows, 1);
for row = 1: rows
col1 = find(binaryImage(row,:), 1, 'first');
col2 = find(binaryImage(row,:), 1, 'last');
if col2-col1 > minRequiredDistance
x(row) = (col1 + col2) / 2;
y(row) = row;
end
end
plot(x, y, 'r-', 'MarkerSize', 8, 'LineWidth', 2);
helpdlg('Done!');
  1 comentario
Inderdeep Grewal
Inderdeep Grewal el 2 de Mayo de 2018
Thank You for the helpful answer! I am new to the image processing side of MATLAB but after looking at the code commands, the process is quite clear on how to break the image down to grayscale and then creating the line minimum distance in order for the line to be marked. I will be sure to try the green channel method as well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by