How can I solve this problem?

1 visualizzazione (ultimi 30 giorni)
Here I attached the warning problem of error. How can I solve this? My source code has been attached here.
  2 Commenti
dpb
dpb il 13 Lug 2019
Use the debugger to step through and see where your logic error is in trying to access too many elements.
One possibility you may not have coded for is that your selection algorithm returned nothing owing to the input image not being able to be processed successfully with whatever algorithm you're using so that even if "Nlargest" is 1 it still fails.
A test for isempty() before you make the attempt would catch that problem.
Syed Zenith Rhyhan
Syed Zenith Rhyhan il 14 Lug 2019
I can't clearly Understand the problem Sir

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 14 Lug 2019
You chose a threshold where there were no blobs. Pick a threshold where you actually have some blobs present.
But you can't because, for some reason, you're trying to segment in HSV colorspace when your image is grayscale. Because R = G = B, there are no colors and so the hue and saturation channels are all zero, and since you use that to threshold, your threshold is zero and your image is zero, hence no blobs at all. Just because you have three color channels doesn't mean that the image will have hue or saturation.
Do not segment a gray scale image in any color space such as RGB or HSV. Just call rgb2gray()
grayImage = rgb2gray(rgbImage);
or take any one of the color channels:
grayImage = rgbImage(:, :, 2); % Use the green channel.
  3 Commenti
Image Analyst
Image Analyst il 14 Lug 2019
Here's a start. Adapt/continue as needed.
%%Author: Zarreen Naowal Reza
%%Email: zarreen.naowal.reza@gmail.com
clc;
clear all;
close all;
fontSize = 20;
rgbImage = imread('input.jpg');
% Display the image.
subplot(2, 3, 1);
imshow(rgbImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
% 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(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 2); % Take green channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% 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;
hp = impixelinfo;
% Make histogram.
subplot(2, 3, 2);
imhist(grayImage);
grid on;
title('Histogram', 'FontSize', fontSize);
%--------------------image threshoiding-------------------------------
threshold = 90;
mask = grayImage > threshold ;
subplot(2, 3, 3);
imshow(mask);
title('Mask', 'FontSize', fontSize);
% Find the areas of all the blobs
props = regionprops(mask, 'Area');
allAreas = sort([props.Area], 'Descend')
% Get rid of blobs smaller than 100 pixels.
mask = bwareaopen(mask, 100);
% Get rid of the skull. Skull will be label #1 since it's the outermost blob.
[labeledImage, numBlobs] = bwlabel(mask);
skullMask = ismember(labeledImage, 1);
% Get mask without skull -- the tumor(s).
insideMask = ismember(labeledImage, 2:numBlobs);
% Optional: fill holes
insideMask = imfill(insideMask, 'holes');
% Display the image.
subplot(2, 3, 4);
imshow(insideMask, []);
title('Tumor Mask', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
% Mask the original image.
maskedImage = grayImage; % Intialize
maskedImage(~insideMask) = 0;
% Display the image.
subplot(2, 3, 5);
imshow(maskedImage, []);
title('Masked Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
0000 Screenshot.png
Syed Zenith Rhyhan
Syed Zenith Rhyhan il 14 Lug 2019
Thanks a lot Sir

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by