필터 지우기
필터 지우기

I have 2D images of black balls and white inter-balls spaces. I want a CNN to recognise the white area. I think it's a grayscale binary image segmentation task

조회 수: 3 (최근 30일)
I have attached one of the image. It's all almost the same. I think that you will find this easy but I really don't have a background in coding
  댓글 수: 5
Image Analyst
Image Analyst 2023년 8월 19일
I can see you needing a CNN if you have real world images. It looks like what you chose to upload was a synthetically created image, that like @DGM said, has already been segmented to find the white areas. If you have some other porosity method obtained by some other method (like air or liquid diffusion or however) then you can use deep learning to do a regression to take the gray scale image and try to predict the porosity. Please post the actual image, not this simplified already-binary one.
help trainNetwork
trainNetwork Train a neural network trainedNet = trainNetwork(imds, layers, options) trains and returns a network trainedNet for a classification problem. imds is an ImageDatastore with categorical labels, layers is an array of network layers or a LayerGraph, and options is a set of training options. trainedNet = trainNetwork(ds, layers, options) trains and returns a network trainedNet using the datastore ds. For single-input networks, the datastore read function must return a two-column table or two-column cell array, where the first column specifies the inputs to the network and the second column specifies the expected responses. For networks with multiple inputs, the datastore read function must return a cell array with N+1 columns, where N is the number of inputs. The first N columns correspond to the N inputs and the final column corresponds to the responses. trainedNet = trainNetwork(X, Y, layers, options) trains and returns a network, trainedNet. The format of X depends on the input layer. - For an image input layer, X is a numeric array of images arranged so that the first three dimensions are the width, height and channels, and the last dimension indexes the individual images. - For a 3-D image input layer, X is a numeric array of 3-D images with the dimensions width, height, depth, channels, and the last dimension indexes the individual observations. - For a feature input layer, X is a numeric array arranged so that the first dimension indexes the individual observations, and the second dimension indexes the features of the data set. - For a point cloud input layer, X is a 3-D or 4-D numeric array of point cloud data arranged so that the second to last dimension indexes the channels and the last dimension indexes the individual observations. The format of Y depends on the type of task. - For a classification task, Y specifies the labels for the data/images as a categorical vector. - For a regression task, Y contains the responses arranged as a matrix of size number of observations by number of responses. When dealing with images, Y can also be specified as a four dimensional numeric array, where the last dimension corresponds to the number of observations. When dealing with point cloud data, Y can also be specified as a three dimensional or four dimensional numeric array, where the last dimension corresponds to the number of observations. trainedNet = trainNetwork(sequences, Y, layers, options) trains an LSTM network for classification and regression problems for sequence or time-series data. layers must define a network with a sequence input layer. sequences must be one of the following: - A cell array of C-by-S matrices, where C is the number of features and S is the number of time steps. - A cell array of H-by-W-by-C-by-S arrays, where H-by-W-by-C is the 2-D image size and S is the number of time steps. - A cell array of H-by-W-by-D-by-C-by-S arrays, where H-by-W-by-D-by-C is the 3-D image size and S is the number of time steps. Y must be one of the following: - For sequence-to-label classification, a categorical vector. - For sequence-to-sequence classification, a cell array of categorical sequences. - For sequence-to-one regression, a matrix of targets. - For sequence-to-sequence regression, a cell array of C-by-S matrices. For sequence-to-sequence problems, the number of time steps of the sequences in Y must be identical to the corresponding predictor sequences. For sequence-to-sequence problems with one observation, the input sequence can be a numeric array, and Y must be a categorical sequence of labels or a numeric array of responses. trainedNet = trainNetwork(tbl, layers, options) trains and returns a network, trainedNet. - For networks with an image input layer, tbl is a table containing predictors in the first column as a cell array of image paths or images. Responses must be in the second column as categorical labels for the images. In a regression problem, responses must be in the second column as either vectors or cell arrays containing 3-D arrays or in multiple columns as scalars. - For networks with a sequence input layer, tbl is a table containing a cell array of MAT file paths of predictors in the first column. For a sequence-to-label classification problem, the second column must be a categorical vector of labels. For a sequence-to-one regression problem, the second column must be a numeric array of responses or in multiple columns as scalars. For a sequence-to-sequence classification problem, the second column must be a cell array of MAT file paths with a categorical response sequence. For a sequence-to-sequence regression problem, the second column must be a cell array of MAT file paths with a numeric response sequence. Support for tables and networks with a sequence input layer will be removed in a future release. For out-of-memory data, use a datastore instead. - For networks with a feature input layer, tbl is a table containing predictors in multiple columns as scalars and responses as a column of categorical labels. For regression tasks, responses must be in multiple columns as scalars or in a single column as a numeric vector. trainedNet = trainNetwork(tbl, responseNames, layers, options) trains and returns a network, trainedNet. responseNames is a character vector, a string array, or a cell array of character vectors specifying the names of the variables in tbl that contain the responses. [trainedNet, info] = trainNetwork(...) trains and returns a network, trainedNet. info contains information on training progress. Example 1: % Train a convolutional neural network on some synthetic images % of handwritten digits. Then run the trained network on a test % set, and calculate the accuracy. [XTrain, YTrain] = digitTrain4DArrayData; layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]; options = trainingOptions('sgdm', 'Plots', 'training-progress'); net = trainNetwork(XTrain, YTrain, layers, options); [XTest, YTest] = digitTest4DArrayData; YPred = classify(net, XTest); accuracy = sum(YTest == YPred)/numel(YTest) Example 2: % Train a long short-term memory network to classify speakers of a % spoken vowel sounds on preprocessed speech data. Then make % predictions using a test set, and calculate the accuracy. [XTrain, YTrain] = japaneseVowelsTrainData; layers = [ ... sequenceInputLayer(12) lstmLayer(100, 'OutputMode', 'last') fullyConnectedLayer(9) softmaxLayer classificationLayer]; options = trainingOptions('adam', 'Plots', 'training-progress'); net = trainNetwork(XTrain, YTrain, layers, options); [XTest, YTest] = japaneseVowelsTestData; YPred = classify(net, XTest); accuracy = sum(YTest == YPred)/numel(YTest) Example 3: % Train a network on synthetic digit data, and measure its % accuracy: [XTrain, YTrain] = digitTrain4DArrayData; layers = [ imageInputLayer([28 28 1], 'Name', 'input') convolution2dLayer(5, 20, 'Name', 'conv_1') reluLayer('Name', 'relu_1') convolution2dLayer(3, 20, 'Padding', 1, 'Name', 'conv_2') reluLayer('Name', 'relu_2') convolution2dLayer(3, 20, 'Padding', 1, 'Name', 'conv_3') reluLayer('Name', 'relu_3') additionLayer(2,'Name', 'add') fullyConnectedLayer(10, 'Name', 'fc') softmaxLayer('Name', 'softmax') classificationLayer('Name', 'classoutput')]; lgraph = layerGraph(layers); lgraph = connectLayers(lgraph, 'relu_1', 'add/in2'); plot(lgraph); options = trainingOptions('sgdm', 'Plots', 'training-progress'); [net,info] = trainNetwork(XTrain, YTrain, lgraph, options); [XTest, YTest] = digitTest4DArrayData; YPred = classify(net, XTest); accuracy = sum(YTest == YPred)/numel(YTest) See also nnet.cnn.layer, trainingOptions, SeriesNetwork, DAGNetwork, LayerGraph. Documentation for trainNetwork doc trainNetwork
Wurood
Wurood 2023년 8월 20일
thamks for this explanation. To be clear, I am in the first step in a project to train the CNN to recognie the porosity in "real worlg images". Those synthetic images will help me to start from scratch. Any way the next step will be adding more grains in a differnt grey color and a different size and train the network to recognize : The small grains, the big grains and the porosity.
Could you guide me to an explaind code so I can move on to the next steps??

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2023년 8월 20일
이동: Image Analyst 2023년 8월 20일
Training with synthetic images and then running on real world images will likely produce inaccurate segmentations and porosity estimates. The most accurate way to count the white pixels is to simply do numWhite = sum(mask, 'all'). If you use deep learning we don't know what it will do. Will it learn to simply threshold and then sum? Or will it do a bunch of convolutions which will blur and downsample your images making them less accurate? For that reason I'd train on the actual images you plan to use, not synthetic ones. To see how to train a network, see the button callback function called btnStartTraining_Callback in the attached m-file
  댓글 수: 5
Wurood
Wurood 2023년 8월 21일
Ok; as I mentioned befor; Since I will be dealing with grayscale images where different ball sizes have distinct grayscale values, and do you think that I need to come up with a labeling scheme that captures this information?
Image Analyst
Image Analyst 2023년 8월 21일
No. With regression you don't need to label or segment the images. You only need to provide the known, measured porosity of the material the image came from. Labeling wouldn't make sense since you're not trying to find non-porous pixels (segment the image) or classify the image into a small discrete number of porosity classes (like none, low, medium, and high porosity).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by