Looking to set thresholds to an image but running into issues with the subplot?

1 visualización (últimos 30 días)
%"sobelpic" is the name of the image.
%I'm getting an error that my subplot is too large.
%I'm thinking that I need to manipulate my threshs (somehow?) because ultimately I need to choose "0.34" as a threshold value according to my professor.
threshs = 0.01:0.01:0.8;
for i =1:length(threshs)
BW = im2bw(sobelpic,threshs(i));
subplot(1,2,i); %I can set this to (1,2,2) to get two images but I need more to choose from.
imagesc(BW);
title(['frame ',num2str(i)]);
end
t = input('which threshold?');
BW = im2bw(sobelpic,threshs(t));
BW = imcomplement(BW);
So ultimately I'd like to see 8 images in a sublot with thresholds from 0 to 1, where 0.34 is one of them. Thank you.
Original image is uploaded, the one I'm using has the sobel filter on it, named "sobelpic" in the code.

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Nov. de 2021
Editada: Image Analyst el 8 de Nov. de 2021
Kristin, try this. Again, no idea what you want to measure but I'm pretty sure Sobel is not the best approach. Why do you think it is?
% Demo by Image Analyst
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;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'drosophila_embryo_wild_type.jpg';
grayImage = imread(fileName);
% 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.
% Extract the blue channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 3);
end
%"sobelpic" is the name of the image.
%I'm getting an error that my subplot is too large.
%I'm thinking that I need to manipulate my threshs (somehow?) because ultimately I need to choose "0.34" as a threshold value according to my professor.
threshs = linspace(0.01, 0.8, 9);
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(4, 3, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
drawnow;
% Get a sobel image.
sobelPic = imgradient(grayImage,"sobel");
subplot(4, 3, 2);
imshow(sobelPic, []);
impixelinfo;
axis('on', 'image');
title('Sobel Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
subplot(4, 3, 3);
histogram(sobelPic);
grid on;
xlim([0, 150]);
title('Histogram of Sobel Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Compute binary image
for k =1:length(threshs)
t = threshs(k);
BW = im2bw(sobelPic,t);
subplot(4, 3, k+3);
imshow(BW, []);
caption = sprintf('Thresholed at %.2f', t);
title(caption);
drawnow;
end
  1 comentario
Kristin Aldridge
Kristin Aldridge el 8 de Nov. de 2021
Thanks. I was struggling with the subplot and managed to find a work-around but couldn't get 0.34 to show. I have no choice in sobel unfortunately, my professor wants me to use it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox 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