Main Content

isequal

(To be removed) Compare two bigimage objects for equality

Since R2019b

The isequal function of the bigimage object will be removed in a future release. Use the blockedImage object instead. For more information, see Compatibility Considerations.

Description

tf = isequal(bigimg1,bigimg2) returns true if big images bigimg1 and bigimg2 have the same spatial referencing, underlying data type, and block size. Pixel values are only compared if the metadata is equal, and the comparison ends early when unequal pixel values are found. isequal does not consider file names, masks, and other class properties.

Input Arguments

collapse all

First big image, specified as a bigimage object.

Second big image, specified as a bigimage object.

Output Arguments

collapse all

Big images bigimg1 and bigimg2 are equal, returned as a logical scalar.

Data Types: logical

Version History

Introduced in R2019b

expand all

R2023b: isequal will be removed

The bigimage object and this function will be removed in a future release. Use blockedImage objects instead. You can compare the equality of two blockedImage objects using the isequal function that ships in MATLAB®.

The functions can return different results because they compare different properties of the objects. The bigimage isequal function does not consider file names, masks, and other class properties when evaluating the equality of two bigimage objects. In contrast, the MATLAB isequal function considers all object properties when evaluating the equality of objects, including the image filenames. Therefore, the MATLAB isequal function determines that blockedImage objects are not equal in more situations than the bigimage isequal function.

To update your code, first create two blockedImage objects to read your image data. If you want to reproduce the behavior of the bigimage object, then follow these steps:

  • Compare the equality of the relevant properties, such as the Channels, ClassUnderlying, and BlockSize properties. Although the blockedImage object does not have a SpatialReferencing property, you can compare related properties such as WorldStart and WorldEnd.

  • If any of these properties are not equal between the two objects, then the objects are not equal.

  • If all of these properties are equal between the two objects, then you can compare the data at each resolution level. Read the data using blockedImageDatastore objects, and determine the data equality using the MATLAB isequal function. To perform the comparison efficiently, start by comparing data at the coarsest resolution level and then compare data at increasingly fine resolution levels.

  • If any block of read data is not equal between the two objects, then the objects are not equal. Otherwise, the objects are equal.

Discouraged UsageRecommended Replacement

This example uses the isequal function to compare the equality of a bigimage objects.

filename = "tumor_091R.tif";
bim1 = bigimage(filename,BlockSize=[100 100]);
bim2 = bigimage(filename,BlockSize=[200 200]);
tf = isequal(bim1,bim2);

Here is approximately equivalent code comparing two blockedImage objects. Use this replacement code when the MATLAB isequal function is sufficient.

filename = "tumor_091R.tif";
bim1 = blockedImage(filename,BlockSize=[100 100]);
bim2 = blockedImage(filename,BlockSize=[200 200]);
tf = isequal(bim1,bim2);

Here is approximately equivalent code comparing two blockedImage objects. Use this replacement code when you need to more closely reproduce the behavior of the bigimage isequal function.

First, compare properties of the blockedImage objects.

filename = "tumor_091R.tif";
bim1 = blockedImage(filename,BlockSize=[100 100]);
bim2 = blockedImage(filename,BlockSize=[200 200]);
tf = isequal(bim1.WorldStart,bim2.WorldStart) ...
      && isequal(bim1.WorldEnd,bim2.WorldEnd) ...
      && isequal(bim1.Size,bim2.Size) ... 
      && isequal(bim1.NumLevels,bim2.NumLevels) ...
      && isequal(bim1.Channels,bim2.Channels) ...
      && isequal(bim1.ClassUnderlying,bim2.ClassUnderlying) ...
      && isequal(bim1.BlockSize,bim2.BlockSize);

If these properties are equal, then you can compare the data for each resolution level.

for lvl = bim1.NumLevels:-1:1
    ds1 = blockedImageDatastore(bim1,lvl); 
    ds2 = blockedImageDatastore(bim2,lvl);
    while tf && hasdata(ds1) && hasdata(ds2)
        tf = isequal(read(ds1),read(ds2));
    end
end

If tf is true, then the objects are equal. Otherwise, the objects are not equal.

See Also