How can I analyze and isolate certain region of 3D plot and create an condition for passing/failing parts?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
William Rose
2022년 7월 25일
@omar soufan, I made a comment back on your original post, which answers some of these quesitons.
답변 (2개)
prabhat kumar sharma
2023년 10월 13일
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
Shubham
2023년 10월 13일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!