Load satellite image in Matlab - image

I've a problem about how can I load a Landsat image on Matlab. My image is in format .img and have the following information:
Columns and rows= 9487 x 8543
Number of bands= 6
Cellsize= 25 x 25
Source Type= continuous
PĂ­xel type= unsigned integer
Pixel Depth= 16 bit
Scale factor= 0,9996
And this is my code:
IM= multibandread('2000.img',[9487, 8543,
6],'int16',0,'ieee-le',{'Row','Range',[9487 8543]);
But there's the following error:
Error: Unbalanced or unexpected parenthesis or bracket.
I've tried to change but it doesn't work. What can I do?
Thanks in advance,
Emma

Dennis is right, you're missing a closing curly brace. It should be inserted between the bracket and the parenthesis at the end like this:
IM= multibandread('2000.img',[9487, 8543, 6],'int16',0,'ieee-le',{'Row','Range',[9487 8543]});

I think you may want to leave the subset argument out completely, this in addition to using unsigned uint16, try the following:
multibandread('2000.img',[9487, 8543, 6],'uint16',0,'ieee-le')
Note that with your current call it appears that you are trying to extract row 9487 to 8543.

Related

Hidden message in a picture

I'd like to read a hidden message in the following picture:
The message is supposed to look like CTF{Something}.
I've tried to find out how to read it for hours without success.
So far, I've tried to read the RGB values of each cell.
For instance, first cell (1, 1) is rgb(88, 101, 114) or #586572.
First three cells would give: Xer, ddnc which obviously makes non sense.
Last cell #587c00 rgb(88, 124, 0) is then supposed to be a }.
The only clue I have to solve that is RGB is a kind of ASCII.
Could you help me to solve that ?
This is an absolute spoiler for the puzzle, but here goes. I did truncate the actual flag out of the message, though, so you'll have some work to do.
With the original image 6x7 image in hand (the 192x224 image in the original post can be losslessly downscaled down to that), convert it to an uncompressed format such as Netpbm PPM, then simply look at the raw data (as the clue says).
$ convert 9TwkJ-6x7.png 9t.ppm
$ cat 9t.ppm
P6
6 7
255
Yes, decoding the colors as ASCII characters was the solution. [...]
You can get to the same result with e.g. Python with
>>> from PIL import Image
>>> im = Image.open("9TwkJ-6x7.png")
>>> im.tobytes()
b'Yes, decoding the colors as ASCII characters was the solution. [...]
A more devilish CTF would have e.g. rotated the source 90 degrees...
As for
For instance, first cell (1, 1) is rgb(88, 101, 114) or #586572. First three cells would give: Xer, ddnc which obviously makes non sense.
that smells like a different color profile wreaking havoc on your data; Yes, deco and Xer, ddnc are all just 1 RGB value here or there...

How to transform one column to much column on matrix using Fortran 90

I have one column (im = 160648) and row (jm = 1). I want to transform that to a matrix with sizes (im = 344) and (jm=467)
my program code is
program matrix
parameter (im=160648, jm=1)
dimension h(im,jm)
integer::h
open (1,file="Hasil.txt", status='old')
open (2,file="HasilNN.txt", status='unknown')
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
do i=1,im
write(2,33)(h(i,j),j=1,jm)
end do
33 format(1x, 344f10.6)
end program matrix
the error code that appears when read(1,*)(h(i,j)),j=1,jm)
the data type is floating data.
Your read loop is:
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
Shouldn't do i=1,jm be do i=1,im ?
This would imply there are "im" records (lines) in the formatted text file Hasil.txt, which your question suggests.
read(1,*)(h(i,j)),j=1,jm) implies each record (line of text) has "jm" values, which is 1 value per line. Is this what the file looks like ? (An unknown number of blank lines will be skipped with this read (lu,*) ... statement.)
You appear to be wanting to write this information to another file; HasilNN.txt using 33 format (1x, 344f10.6) which suggests 3441 characters per line, although your write statement will write only 1 value per line (as jm=1). This would be a very long line for a text file and probably difficult to manage outside the program. If you did wish to do this, you could achieve this with an implied do loop, such as:
write(2,33) ((h(i,j),j=1,jm),I=1,im)
A few comments:
using jm = 1 implies each row has only one value, which could be equivalently represented as a 1d vector "dimension h(im)", negating the need for j
File unit numbers 1 and 2 are typically reserved unit numbers for screen/keyboard. You would be better using units 11 and 12.
When devising this code, you need to address the record structure in the 2 files, as a simple vector could be used. You can control the line length with the format. A format of (1x,8f10.6) would create a record of 81 characters, which would be much easier to manage.
Format descriptor f10.6 also limits the range of values you can manage in the files. Values >= 1000 or <= -100 will overflow this format, while values smaller than 1.e-6 will be zero.
As #francescalus has noted, you have declared "h" as integer, but use a real format descriptor. This will produce an "Error : format-data mismatch" and has to be changed to what is expected in the file.
You should consider what you wish to achieve and adjust the code.

Cannot use scatterplot in Octave

I was learning how to do machine learning on mldata.org and I was watching a video on Youtube on how to use the data (https://www.youtube.com/watch?v=zY0UhXPy8fM) (2:50). Using the same data, I tried to follow exactly what he did and create a scatterplot of the dataset. However when he used the scatterplot command, it worked perfectly on his side, but I cannot do it on myside.
Can anyone explain what's wrong and what I should do?
octave:2> load banana_data.octave
octave:3> pkg load communications
octave:4> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
data 2x5300 84800 double
label 1x5300 42400 double
Total is 15900 elements using 127200 bytes
octave:5> scatterplot(data, label)
error: scatterplot: real X must be a vector or a 2-column matrix
error: called from:
error: /home/anthony/octave/communications-1.2.0/scatterplot.m at line 69, column 7
The error message says it all. Your data is a 2-row matrix, and not a 2-column matrix as it should be. Just transpose it with .'.
scatterplot(data.')
I dropped the label argument since it is not compatible with the communications toolbox, either in matlab or in octave.
Update:
According to news('communications'),
The plotting functions eyediagram' andscatterplot' have improved Matlab compatibility
This may be why the behaviour is different. Be ready to find other glitches, as the octave 3.2.4 used in this course is about 5 years old.
In order to use the label, you should rather use the standard octave scatter function.
Colors could be changed by choosing another colormap.
colormap(cool(256))
scatter(data(1,:), data(2,:), 6, label, "filled")

MATLAB - image huffman encoding

I have a homework in which i have to convert some images to grayscale and compress them using huffman encoding. I converted them to grayscale and then i tried to compress them but i get an error. I used the code i found here.
Here is the code i'm using:
A=imread('Gray\36.png');
[symbols,p]=hist(A,unique(A))
p=p/sum(p)
[dict,avglen]=huffmandict(symbols,p)
comp=huffmanenco(A,dict)
This is the error i get. It occurs at the second line.
Error using eps
Class must be 'single' or 'double'.
Error in hist (line 90)
bins = xx + eps(xx);
What am i doing wrong?
Thanks.
P.S. how can i find the compression ratio for each image?
The problem is that when you specify the bin locations (the second input argument of 'hist'), they need to be single or double. The vector A itself does not, though. That's nice because sometimes you don't want to convert your whole dataset from an integer type to floating precision. This will fix your code:
[symbols,p]=hist(A,double(unique(A)))
Click here to see this issue is discussed more in detail.
first, try :
whos A
Seems like its type must be single or double. If not, just do A = double(A) after the imread line. Should work that way, however I'm surprised hist is not doing the conversion...
[EDIT] I have just tested it, and I am right, hist won't work in uint8, but it's okay as soon as I convert my image to double.

Matlab big matrix

I'm trying to use matlab for the first time but I'm having a problem because the matrix I'm using is too big, I think.. I command I'm trying is:
m=[1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;169201]7;531456;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017;1692017]
And I'm getting the following error: Error: Unexpected MATLAB expression.
Does anyone have a solution for this?
Thanks in advance !
That matrix is tiny :-) Matlab can handle millions of elements per matrix.
However, on the second line, you have an extra bracket that ruins things:
...17;1692017;169201 ] 7;5...
Get rid of it, and you'll be fine!
Seems like you are trying to do a matrix, but typing its code wrongly. First, the ; separates lines; if you want to separaate columns in a row you have to use a space.
And you have two closing ], while you have only one opening [ which is clearly incorrect

Resources