How to generate perimeter around the sub pixel image.

7 visualizaciones (últimos 30 días)
ProblemSolver
ProblemSolver el 24 de Mayo de 2022
Comentada: ProblemSolver el 26 de Mayo de 2022
Hello,
1) This above image has very bright white spot in the center, and a faint blue surrounding it (acting as a subpixel level)(Left). I am struggling to create the periphery around that blue pixels, and not the white spot. I am using the general code, that the matlab image processing tool provides, I am only able to generate the periphery around the white spot (Right).
2) I enhanced the contrast using the rgb color (left) but, the image looses its value, and the details I need to extract are not valid anymore (Right). The contrast enhanced is as shown below:
Therefore, I need to generate Final_Image_2 using 64882.jpg image. In other words, image (1,1) and results corresponding to image (2,2)
Regards,

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Mayo de 2022
You don't need to enhance the contrast. Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = '64882.jpg';
folder = pwd;
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
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Crop off screenshot stuff
% rgbImage = rgbImage(132:938, 352:1566, :);
% Display image.
subplot(2, 3, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% 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')
drawnow;
% Take one of the color channels, whichever one seems to have more contrast..
colorChannelToUse = 3;
grayImage = rgbImage(:, :, colorChannelToUse);
% Display the color segmentation mask image.
subplot(2, 3, 2);
imshow(grayImage, []);
caption = sprintf('Color Channel %d', colorChannelToUse)
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
%=======================================================================================
% Show the histogram
subplot(2, 3, [3, 6]);
imhist(grayImage);
grid on;
caption = sprintf('Histogram of Color Channel %d', colorChannelToUse)
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize)
ylabel('Count', 'FontSize', fontSize)
%=======================================================================================
% Threshold the image to get the disk.
lowThreshold = 96;
highThreshold = 255;
% Use interactive File Exchange utility by Image Analyst to to the interactive thresholding.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(114, 255, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Now do clean up by hole filling, and getting rid of small blobs.
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1); % Take largest blob only.
% Display the color segmentation mask image.
subplot(2, 3, 4);
imshow(mask, []);
title('Final Mask', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
% Get x and y
boundary = bwboundaries(mask);
x = boundary{1}(:, 2);
y = boundary{1}(:, 1);
subplot(2, 3, 1);
%=======================================================================================
% Find the area and equivalent circular diameter.
props = regionprops(mask, 'Centroid', 'EquivDiameter', 'Area');
% Display image with blob outlined over it.
subplot(2, 3, 5);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Area = %d pixels. ECD = %.1f pixels.', props.Area, props.EquivDiameter);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Display boundary
hold on;
plot(x, y, 'r-', 'LineWidth', 2);
% Plot centroid.
plot(props.Centroid(1), props.Centroid(2), 'r+', 'LineWidth', 2, 'MarkerSize', 20);
%=======================================================================================
findBoundingCircle = false;
if findBoundingCircle
% Find the minimum bounding circle using John D'Errico's File Exchange
% https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal-bounding-objects?s_tid=srchtitle
% Get the minimum bounding circle.
hullflag = true;
[center,radius] = minboundcircle(x,y,hullflag)
% Show circle
viscircles(center, radius, 'color', 'r');
caption = sprintf('With Boundary and Bounding Circle');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
end
uiwait(helpdlg('Done!'));
I don't know what you want to do after that. You said something vague about "the details I need to extract" but didn't say what those were.
  4 comentarios
Image Analyst
Image Analyst el 26 de Mayo de 2022
Looks like you're doing it already. Processing time should be a fraction of a second. I don't think you can speed up regionprops any. Perhaps with the parallel processing toolbox but that would probably only speed it up if you had thousands of blobs, not for just 1 or 2.
ProblemSolver
ProblemSolver el 26 de Mayo de 2022
@Image Analyst I agree. I usually put this in a for loop as I have like 100 images extracted from the video. and then post processing each image. But the only problem I faced now is having an image with these two diffrerent densed blue continum, and I want to figure out what is the area of both blobs separately. I tried using establishing how you did in the previous example for the image.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by