I am trying to perform operations on images that are in the .img format. I am able to open the files in Matlab. I want to perform manual cropping (using computer mouse) on those files without converting it into jpeg/png or other formats. The result is shown in e4.fig file which is not correct. I am unable to attach the TM570007_LML_08_06.img file as it is not supported in this forum. Any suggestions would be appreciated.
I=imageload('D:\regionGrowing_MLT\TM570007_LML_08_06.img');
imshow(I,[])
% Display image
% imshow(im);
% Use GETRECT to select a rectangle region by using the mouse
sp=getrect;
% Get the x and y co-ordinates
sp(1) = max(floor(sp(1)), 1); %xmin
sp(2) = max(floor(sp(2)), 1);%ymin
sp(3)= min(ceil(sp(1) + sp(3))); %xmax
sp(4)=min(ceil(sp(2) +sp(4))); %ymax
% Index into the original image to create the new image
MM=I(sp(2):sp(4), sp(1): sp(3),:);
image(MM)
set(gca,'Visible','off')

 Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 30 Mär. 2021
Bearbeitet: Kojiro Saito am 30 Mär. 2021

0 Stimmen

UPDATED ANSWER
Thank you. I've tested both img files. Suppose you want to clip the image, you just need to do
imshow(MM, [])
instead of image(MM). Because image requires color matrix data, but your img file is a grayscale image.
ORIGINAL ANSWER
I'm not sure what is the root cause of this issue without an actual img file, but you're using R2020b you can use readgeoraster function for ERDAS IMAGIN file (.img). Mapping Toolbox is requred, but it's more easier.
Instead of using imageload, how about using readgeoraster?
I = readgeoraster('D:\regionGrowing_MLT\TM570007_LML_08_06.img');

5 Kommentare

Warid Islam
Warid Islam am 30 Mär. 2021
Hi Kojiro,
I tried, but I get the following error.
Error using readgeoraster (line 97)
Unable to read 'TM570007_LML_08_06.img'. Format may not be supported, file may be corrupt, or a
supporting file may have been specified.
Kojiro Saito
Kojiro Saito am 30 Mär. 2021
All right, your img file might be a special format. Could you attach the sample img file by changing the file extension to zip?
Warid Islam
Warid Islam am 30 Mär. 2021
Hi Kojiro,
Please find a couple of .img files in zipped format.
Kojiro Saito
Kojiro Saito am 30 Mär. 2021
Thank you for sharing the img files. I've updated my answer.
Warid Islam
Warid Islam am 30 Mär. 2021
It worked. Thanks a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Geographic Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by