How can I analyze and isolate certain region of 3D plot and create an condition for passing/failing parts?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
im1=imread('knifetest.jpg');
zr=im1(:,:,1); %get the red intensity array
zg=im1(:,:,2); %get the green intensity array
zb=im1(:,:,3); %get the blue intensity array
[r,c]=size(zg); %image dimension
subplot(2, 1, 1);
imshow(im1);
title('RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Set up figure properties:
subplot(2, 1, 2);
grid on;
hold on;
surf(1:c,1:r,zg,'EdgeColor','none'); %surface plot of green intensity
zlabel('Green Intensity')
%% How do I isolate a certain region in the surface to analyze and create a pass/fail condition. Example: if the green intensity in the middle is larger than X or the area of green is present inside a certain region is larger than X value, then sample fails
Also, can I plot a 2d image and its surf plot on the same plot using subplot?
Code credit to William Rose
2 Kommentare
William Rose
am 25 Jul. 2022
@omar soufan, I made a comment back on your original post, which answers some of these quesitons.
Antworten (2)
prabhat kumar sharma
am 13 Okt. 2023
Hi OmartheEngineer,
I understand that you are facing issue with isolating a region based on condition.
I found out a way that this can be done using the threshold value of area and intensity in the green channel of image. You can see below code for reference.
% Define the threshold values for pass/fail condition
thresholdIntensity = X; % Replace X with the desired threshold intensity value
thresholdArea = Y; % Replace Y with the desired threshold area value
% Create a binary mask based on the green intensity threshold
passMask = zg > thresholdIntensity;
% Calculate the area of the pass region
passArea = sum(passMask(:));
% Check the pass/fail condition
if passArea > thresholdArea
disp('Sample fails');
else
disp('Sample passes');
end
And plotting a 2d image and it’s surf plot on the same plot is already done in the code provided.
Regards,
Prabhat Sharma
0 Kommentare
Shubham
am 13 Okt. 2023
I understand that you want to isolate a region in the image and then analyse it.
The “imread” function returns a matrix consisting of indices and colour values for the pixels. Refer to the following example from the documentation:
[X,cmap] = imread('corn.tif');
You can isolate the region of your interest from the matrix values. For example, refer to the following code snippet:
grayImage = imread('pout.tif');
imshow(grayImage);
figure;
sliceOfImage = grayImage(:,1:50);
imshow(sliceOfImage);
The above code snippet crops the image such that only first 50 columns of the matrix are used to show the image. Here is the output produced by the above code snippet:
You can also manually select the region of interest using functions such as “imrect” and “imcrop”. Refer to this previous MATLAB answer for extracting a region from the image:
Once you obtain the region of interest you can easily analyse colour intensities by comparing with a threshold value.
Also, for plotting a 2D image and its surf plot on the same plot using subplot can be achieved. Here is an example code snippet:
% Load the image
im1 = imread('peppers.png');
% Create a new figure
figure;
% Plot the 2D image
subplot(1, 2, 1);
imshow(im1);
title('RGB Image');
% Plot the surface plot
subplot(1, 2, 2);
surf(1:c, 1:r, zg, 'EdgeColor', 'none');
title('Surface Plot of Green Intensity');
xlabel('Column');
ylabel('Row');
zlabel('Green Intensity');
It produces the following output:
Hope this helps!!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!