Generating the edge for a higher intensity pixels and not low intensity pixels.

3 次查看(过去 30 天)
Hello Image Processing Committee ---
I have tried several ways to isolate the high intensity blue pixels fromt he low intensity pixels. using bilateral filtering method and an example shown below. I am unable to create a shape around the image provided below. The shape should be around the higher intensity blue pixels and not the low intensity pixels. Plus, if possible to apply Otsu thresholding in such condition?
Thank you for you help.
Best regards,
% Read the image
close all; clear all;
ImageData = imread('Trial.jpg');
Error using imread>get_full_filename
File "Trial.jpg" does not exist.

Error in imread (line 372)
fullname = get_full_filename(filename);
% Convert the image to grayscale
RGBImage = imgaussfilt(ImageData,3);
GrayImage = RGBImage(:,:,3);
% Convert the grayscale image to double precision
ImageDataGray = im2double(GrayImage);
% Define the threshold values for edge detection
lowThreshold = 0.6;
highThreshold = 0.9;
% Apply Canny edge detection
edgeImage = edge(ImageDataGray, 'Canny', [lowThreshold, highThreshold]);
% Display the images in subplots
figure;
% Original Image
subplot(1, 3, 1);
imshow(ImageData);
title('Original Image');
% Grayscale Image
subplot(1, 3, 2);
imshow(ImageDataGray);
title('Grayscale Image');
% Edge Image
subplot(1, 3, 3);
imshow(edgeImage);
title('Edge Detection');
% Find connected components in the edge image
CC = bwconncomp(edgeImage);
numObjects = CC.NumObjects;
% Process each connected component
for k = 1:numObjects
% Extract the k-th object
BW = false(size(edgeImage));
BW(CC.PixelIdxList{k}) = true;
% Calculate the properties of the object using regionprops
P = regionprops(BW, 'Centroid', 'BoundingBox', 'Area', 'Perimeter');
% Filter out faint intensity objects based on area
thresholdArea = 50; % Adjust this value as per your requirement
if P.Area > thresholdArea
% Extract the necessary properties
xCenter = P.Centroid(1);
yCenter = P.Centroid(2);
Area = P.Area;
BoundingBox = P.BoundingBox;
% Plot the boundary and center of the detected object on the image
figure;
imshow(ImageData);
hold on;
rectangle('Position', BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
plot(xCenter, yCenter, 'g+', 'MarkerSize', 10, 'LineWidth', 2);
hold off;
end
end
  1 个评论
ProblemSolver
ProblemSolver 2023-6-27
编辑:ProblemSolver 2023-6-27
As, it can be seen that the low intensity image is in the background, and a high intensity image is in foreground. I need to draw shape for both the intensities separately.
Thank you for your help.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2023-6-27
Not sure what you call low intensity. So if the high intensity mask is all pixels above some threshold, then isn't the low intensity mask just the inverse of that? In other words the whole image except the spot in the middle? And the spot in the middle does not have sharp edges so where the edge of it is, is actually a judgment call. You can get different diameters just by specifying different thresholds. I don't think you need bilateral filteringg or edge detection at all. Why do you think you do? Don't spend time doing unnecessary operations. What are you going do to once you have the high and low intensity masks? That will help me decide what operations other than thresholding that you need to do.
  5 个评论
Image Analyst
Image Analyst 2023-6-29
Using a fixed threshold is best. It's the most reliable, robust, and repeatable. If you're not able to use a fixed threshold, you have to ask yourself why. Do you not have good control over your image capture conditions like lighting and camera settings? If not, try to control them so that the picture is largely the same, like the intensity is the same and only the diameter changes. Then you can use a fixed threshold and get an accurate diameter. If you have to change both the threshold because the settings change and also the object itself changes then you will have noisier results because as I already said you can get different diameters depending on the threshold. So the measured diameter would be changing not only due to the subject/object itself changing but also due to adjustments in the threshold. Try to avoid automatic threshold selection if at all possible and correct your image capture situation instead.
ProblemSolver
ProblemSolver 2023-6-29
编辑:ProblemSolver 2023-6-29
@Image Analyst - Yes, I completely understand. Thats the reason before you wrote this answer, I already accepted your answer. I did check the accuracy of my camera of my camera and the light setting, the skewness, sauration of the pixels, etc. to validate if the camera setting can be refined more. However, the camera setting were set and the parallelisim between the CMOS chip and the window was accurate within an uncertainty was within less than 1.045%.
Thank you for the help.

请先登录,再进行评论。

更多回答(1 个)

DGM
DGM 2023-6-27
移动:DGM 2023-6-27
If you're wanting to identify regions by intensity, why are you using edgefinding? Edgefinding is sensitive to gradient, not to intensity.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1420743/image.jpeg');
% i'm not sure which areas you're trying to select
% i'm going to select the whitish peak separately from the blue disk
% if the two are to be exclusive sets, then just use boolean ops to combine the two
peakmk = inpict(:,:,1) > 26;
mainmk = inpict(:,:,3) > 103;
imshow(peakmk)
imshow(mainmk)
If you want to reduce those to masks delineating the mask boundary, use bwperim() or bwboundary() on the corresponding mask.
  3 个评论
DGM
DGM 2023-6-27
It's hard to come up with a method that will work for varied images based on a single sample image. We'd need to know how the images can plausibly vary -- both the manner in which they vary and the degree to which they vary.
ProblemSolver
ProblemSolver 2023-6-27
I understand. The pictures plausible changes are as such shown in the these three images. In the first picture you have only the low intensity pixels, then in the next one you have low and high intensity pixels, and finally you have the low-intensity pixels are almost equivalent to the high-intensity pixels.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by