diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/invert_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/invert_op.cc index ef2326ca5c8..863b4d7a011 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/invert_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/invert_op.cc @@ -32,27 +32,22 @@ Status InvertOp::Compute(const std::shared_ptr &input, std::shared_ptrmat().data) { RETURN_STATUS_UNEXPECTED("Invert: load image failed."); } - if (input_cv->Rank() != 3 && input_cv->Rank() != 2) { - RETURN_STATUS_UNEXPECTED("Invert: image shape is not or "); + + if (input_cv->Rank() != 3) { + RETURN_STATUS_UNEXPECTED("Invert: image shape is not "); } - int num_channels = 1; - if (input_cv->Rank() == 3) { - num_channels = input_cv->shape()[2]; - } - if (num_channels != 3 && num_channels != 1) { - RETURN_STATUS_UNEXPECTED("Invert: image shape is incorrect, expected num of channels is 1 or 3, but got:" + + int num_channels = input_cv->shape()[2]; + if (num_channels != 3) { + RETURN_STATUS_UNEXPECTED( + "Invert: image shape is incorrect, expected num of channels is 3, " + "but got:" + std::to_string(num_channels)); } std::shared_ptr output_cv; RETURN_IF_NOT_OK(CVTensor::CreateEmpty(input_cv->shape(), input_cv->type(), &output_cv)); RETURN_UNEXPECTED_IF_NULL(output_cv); - if(num_channels == 3){ - output_cv->mat() = cv::Scalar::all(255) - input_img; - } - else{ - output_cv->mat() = cv::Scalar(255) - input_img; - } + output_cv->mat() = cv::Scalar::all(255) - input_img; *output = std::static_pointer_cast(output_cv); } @@ -63,4 +58,3 @@ Status InvertOp::Compute(const std::shared_ptr &input, std::shared_ptr