MATLAB Answers

0

Error using horzcat Dimensions of matrices being concatenated are not consistent.

Asked by Nabeela Firdous on 24 Oct 2019
Latest activity Edited by Stephan
on 24 Oct 2019
I want to parse another another value say hsv in featurestatistical fuction but this is showing the above error. Anyone who can help me to resolve this. I'll be thankfull.
Training code
clc;
clear all;
close all;
% Taking an Image
[fname, path]=uigetfile('.png','Open an Image as input for training');
fname=strcat(path, fname);
im=imread(fname);
imshow(im);
title('Input Image');
imgray=rgb2gray(im);
imshow(imgray);
hsv=rgb2hsv(im);
imshow(hsv);
title('HSV Image');
c=input('Enter the Class(Number from 1-12)');
*Fuction code*
function [F]=FeatureStatistical(im)
% Summary of this function goes here
im=double(im);
m=mean(mean(im));
s=std(std(im));
hsv=rgb2hsv(im);
F=[m s hsv];
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 24 Oct 2019
Edited by Stephan
on 24 Oct 2019

Do the following (i did for an example image on my computer):
im = imread('*:\***\***\****.PNG');
im=double(im);
m=mean(mean(im));
s=std(std(im));
hsv=rgb2hsv(im);
imshow(hsv)
F=[m s];
Then this in command line:
>> whos m s hsv
results in something like:
Name Size Bytes Class Attributes
hsv 561x597x3 8038008 double
m 1x1x3 24 double
s 1x1x3 24 double
Now:
>> F = [m s]
F(:,:,1) =
245.0794 14.4569
F(:,:,2) =
245.0877 14.4241
F(:,:,3) =
242.5142 18.1642
which means
>> whos F
Name Size Bytes Class Attributes
F 1x2x3 48 double
You can not add hsv to this array, because its dimension are incompatible:
>> F = [F hsv]
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
>> whos F hsv
Name Size Bytes Class Attributes
F 1x2x3 48 double
hsv 561x597x3 8038008 double

  0 Comments

Sign in to comment.