close all; clear all; clc;

% Read image
img = multibandread('1a.bil',[2400 1600 462],'uint16',0,'bil','ieee-le');

wavelength = [386.88 388.19 389.5 390.81 392.12 393.43 394.74 396.05 397.36 398.67 399.98 401.29 402.6 403.91 405.22 406.53 407.84 409.15 410.46 411.77 413.09 414.4 415.71 417.02 418.33 419.64 420.96 422.27 423.58 424.89 426.21 427.52 428.83 430.15 431.46 432.77 434.09 435.4 436.71 438.03 439.34 440.65 441.97 443.28 444.6 445.91 447.23 448.54 449.86 451.17 452.49 453.8 455.12 456.43 457.75 459.07 460.38 461.7 463.01 464.33 465.65 466.96 468.28 469.6 470.91 472.23 473.55 474.86 476.18 477.5 478.82 480.14 481.45 482.77 484.09 485.41 486.73 488.04 489.36 490.68 492.0 493.32 494.64 495.96 497.28 498.6 499.92 501.24 502.56 503.88 505.2 506.52 507.84 509.16 510.48 511.8 513.12 514.44 515.76 517.08 518.41 519.73 521.05 522.37 523.69 525.02 526.34 527.66 528.98 530.3 531.63 532.95 534.27 535.6 536.92 538.24 539.57 540.89 542.21 543.54 544.86 546.18 547.51 548.83 550.16 551.48 552.81 554.13 555.46 556.78 558.11 559.43 560.76 562.08 563.41 564.73 566.06 567.39 568.71 570.04 571.37 572.69 574.02 575.35 576.67 578.0 579.33 580.65 581.98 583.31 584.64 585.96 587.29 588.62 589.95 591.28 592.61 593.93 595.26 596.59 597.92 599.25 600.58 601.91 603.24 604.57 605.9 607.23 608.56 609.89 611.22 612.55 613.88 615.21 616.54 617.87 619.2 620.53 621.86 623.19 624.52 625.86 627.19 628.52 629.85 631.18 632.52 633.85 635.18 636.51 637.85 639.18 640.51 641.84 643.18 644.51 645.84 647.18 648.51 649.85 651.18 652.51 653.85 655.18 656.52 657.85 659.19 660.52 661.86 663.19 664.53 665.86 667.2 668.53 669.87 671.2 672.54 673.88 675.21 676.55 677.88 679.22 680.56 681.89 683.23 684.57 685.91 687.24 688.58 689.92 691.25 692.59 693.93 695.27 696.61 697.95 699.28 700.62 701.96 703.3 704.64 705.98 707.32 708.66 710.0 711.33 712.67 714.01 715.35 716.69 718.03 719.37 720.71 722.06 723.4 724.74 726.08 727.42 728.76 730.1 731.44 732.78 734.13 735.47 736.81 738.15 739.49 740.84 742.18 743.52 744.86 746.21 747.55 748.89 750.24 751.58 752.92 754.27 755.61 756.95 758.3 759.64 760.99 762.33 763.67 765.02 766.36 767.71 769.05 770.4 771.74 773.09 774.43 775.78 777.12 778.47 779.82 781.16 782.51 783.85 785.2 786.55 787.89 789.24 790.59 791.93 793.28 794.63 795.98 797.32 798.67 800.02 801.37 802.72 804.06 805.41 806.76 808.11 809.46 810.81 812.16 813.5 814.85 816.2 817.55 818.9 820.25 821.6 822.95 824.3 825.65 827.0 828.35 829.7 831.05 832.4 833.75 835.11 836.46 837.81 839.16 840.51 841.86 843.21 844.57 845.92 847.27 848.62 849.97 851.33 852.68 854.03 855.39 856.74 858.09 859.44 860.8 862.15 863.51 864.86 866.21 867.57 868.92 870.28 871.63 872.98 874.34 875.69 877.05 878.4 879.76 881.11 882.47 883.82 885.18 886.54 887.89 889.25 890.6 891.96 893.32 894.67 896.03 897.39 898.74 900.1 901.46 902.81 904.17 905.53 906.89 908.25 909.6 910.96 912.32 913.68 915.04 916.39 917.75 919.11 920.47 921.83 923.19 924.55 925.91 927.27 928.63 929.99 931.35 932.71 934.07 935.43 936.79 938.15 939.51 940.87 942.23 943.59 944.95 946.31 947.67 949.04 950.4 951.76 953.12 954.48 955.85 957.21 958.57 959.93 961.29 962.66 964.02 965.38 966.75 968.11 969.47 970.84 972.2 973.56 974.93 976.29 977.66 979.02 980.38 981.75 983.11 984.48 985.84 987.21 988.57 989.94 991.3 992.67 994.04 995.4 996.77 998.13 999.5 1000.86 1002.23 1003.6];

hcube = hypercube(img,wavelength); 

% Display the image
rgbImg = colorize(hcube,'Method','RGB','ContrastStretching',true); 
figure(1), imshow(rgbImg)

row = 291:1314;
column = 360:1383;

% Crop the Region Of Interest (ROI)
cropped_hcube = cropData(hcube,row,column,':');

% Display the cropped image
rgbImg2 = colorize(cropped_hcube,'Method','RGB','ContrastStretching',true); 
figure(2), imshow(rgbImg2)