Combining an image and shapefile in MATLAB - image

I've been trying to combine an image produced from a deforestation database called Hansen and a shapefile created in ArcGIS to make a georeference image. The script I've written so far is below but unable to figure out how to combine the two (I've tried several scripts including http://uk.mathworks.com/help/map/examples/creating-maps-using-mapshow.html?searchHighlight=overlay%20maps). Any assistance would be helpful!
Thank you,
Michelle
% Read in thresholded Hansen data
Data_FrenchGuiana = imread('FrenchGuiana_GFC_extract_thresholded.tif');
LossYear_FrenchGuiana = Data_FrenchGuiana(:,:,2);
LossYear_FrenchGuiana = double(LossYear_FrenchGuiana);
figure('color','white');
image(LossYear_FrenchGuiana)
imwrite(A,'LossYear_FrenchGuiana.tif')
country = shaperead('FrenchGuiana.shp');
figure mapshow(country);
xlabel('easting in meters')
ylabel('northing in meters')

Related

Co-locate NetCDF and Tiff file

How to co-located two images using Python?
I have two very distinct files:
One is a TIF image (Sentinel-1 image) exported from Google Earth Engine, covering the whole region of the Arctic. You can download it here: https://drive.google.com/uc?export=download&id=1YvNp5lFUE7MzheFGQcHOQdel-GJUQDUl
The other is a NetCDF file (download it here: https://drive.google.com/uc?export=download&id=1i4OGCQhKlZ056H1YHq4hTb0EbEkl-pYd), that covers also the region of the Arctic. In addition to this one I have another NC files with the coordinates (can be downloaded here: https://drive.google.com/uc?export=download&id=1WVzZ--NnHSPkJmBqlGwXAN7abXM5_uNh).
Question is: How to collocate them?
I've tried to upload the NetCDF file (after converting it into a TIF) into Earth engine, but since it doesn't have a fixed grid it doesn't work. So this one is not a solution.
I tried to convert NetCFD into a tif, using:
gdal_translate -of GTiff NETCDF:"C:\PHD\leeModisMPF\MODIS_Meltpond_Fraction_CPOM_5km_daily_2020182.nc":daily_fraction C:\PHD\dom2.tiff -a_srs EPSG:4326 -a_ullr -180 57,8 180 90
and then, I tried to merge/stack them using:
import rioxarray
from rioxarray import merge
from rasterio.plot import show
items = [r'C:\PHD\fri1.tiff',
r'C:\PHD\S1image_2022_02_18.tif']
elements = []
for val in items:
rds = rioxarray.open_rasterio(val)
if rds.rio.crs != "EPSG:32643":
rds = rds.rio.reproject("EPSG:32643")
elements.append(rds)
merged = merge.merge_arrays(elements)#, nodata=0.0)
image = merged.values
show(image)
Btw: in the last case, I never used the NetCDF coordinate file..which could be important to ensure that both tiff and orginal nc have both the same coordinates...

Filtering in DIP using Matlab

I have a CT image of a lung as shown below :
I am trying to filter the inner of the two lungs such that i only remove the thin lines of the bronchi ,but i need to keep these small "circles " as much as i can for extraction in the next step as these small circles are nodules candidates ( cancerous structures ) . So please if you can mention to me a good filtering technique for this purpose. Thanks in advance
You can try imfilter, with Gaussian, or perhaps disk filter. Try:
img=imread('orsoR.png');
h = fspecial('disk',5);
y = imfilter(h, img);
figure;
imshow(y)

Background segmentation from multiple files.jpeg

I am trying to cut off background from currency notes. I used a blobsDemo.m codes I found here, used on coins.jpeg. it worked we quite well for me, on one note.
But when I tried it on multiple images, it returns results on just one note:
For k=1:16
JpegFileName=sprintf('%d.jpeg',k);
Fullfilename=fullfile('Folder',jpegfilename);
Imagedata=imread(Fullfilename)
Originalimage=rgb2gray(imagedata);
Subplot(4,4,k)
Imshow(original image);%displays all my 16 distinct images.
%but when I run
ThresholdValue(k)=100
Binaryimage=originalimage>threshold. value(k);
%it returns for one image.
End
What am I doing wrong please? I need help. Thankyou
for example if your resultant image is stored in variable "IM_out" then use IM_out(:,:,k)

Caffe Multiple Input Images

I'm looking at implementing a Caffe CNN which accepts two input images and a label (later perhaps other data) and was wondering if anyone was aware of the correct syntax in the prototxt file for doing this? Is it simply an IMAGE_DATA layer with additional tops? Or should I use separate IMAGE_DATA layers for each?
Thanks,
James
Edit: I have been using the HDF5_DATA layer lately for this and it is definitely the way to go.
HDF5 is a key value store, where each key is a string, and each value is a multi-dimensional array. Thus, to use the HDF5_DATA layer, just add a new key for each top you want to use, and set the value for that key to store the image you want to use. Writing these HDF5 files from python is easy:
import h5py
import numpy as np
filelist = []
for i in range(100):
image1 = get_some_image(i)
image2 = get_another_image(i)
filename = '/tmp/my_hdf5%d.h5' % i
with hypy.File(filename, 'w') as f:
f['data1'] = np.transpose(image1, (2, 0, 1))
f['data2'] = np.transpose(image2, (2, 0, 1))
filelist.append(filename)
with open('/tmp/filelist.txt', 'w') as f:
for filename in filelist:
f.write(filename + '\n')
Then simply set the source of the HDF5_DATA param to be '/tmp/filelist.txt', and set the tops to be "data1" and "data2".
I'm leaving the original response below:
====================================================
There are two good ways of doing this. The easiest is probably to use two separate IMAGE_DATA layers, one with the first image and label, and a second with the second image. Caffe retrieves images from LMDB or LEVELDB, which are key value stores, and assuming you create your two databases with corresponding images having the same integer id key, Caffe will in fact load the images correctly, and you can proceed to construct your net with the data/labels of both layers.
The problem with this approach is that having two data layers is not really very satisfying, and it doesn't scale very well if you want to do more advanced things like having non-integer labels for things like bounding boxes, etc. If you're prepared to make a time investment in this, you can do a better job by modifying the tools/convert_imageset.cpp file to stack images or other data across channels. For example you could create a datum with 6 channels - the first 3 for your first image's RGB, and the second 3 for your second image's RGB. After reading this in using the IMAGE_DATA layer, you can split the stream into two images using a SLICE layer with a slice_point at index 3 along the slice_dim = 1 dimension. If further down the road, you decide that you want to load even more complex assortments of data, you'll understand the encoding scheme and can write your own decoding layer based off of src/caffe/layers/data_layer.cpp to gain full control of the pipeline.
You may also consider using HDF5_DATA layer with multiple "top"s

Matlab - Symmetric PSD of an Image using fft

I wanted to have one dimensional PSD for an Image calculated (along rows and columns separately) using matlab.
I use the following snippet for the same.
F=fft(img,[],2);%FFT along dim2
F=fftshift(F,2);
mtf=(abs(F)).^2;
mtf_mean = mean(mtf,2);% Mean of all contents of a row
mtf_mean_norm = mtf_mean/max(max(mtf_mean)); %Normalization to 1
plot(mtf_mean_norm);
When I plot it, I expected a symmetrical plot with respect to a center (and that's what I want). But, I happen to see that two parts look asymmerical like in the attached figure.
Looks like I have a code bug, Any clues what am I missing ?
Image url: http://i.stack.imgur.com/RrLIt.jpg
I am not an image processing person, but just from my own stats knowledge I would say.
you should use mtf=abs(F)'*abs(F) instead of mtf=(abs(F)).^2. I got the following figure
here is the code that generates the figure.
> img=randn(50,50);
> F=fft(img,[],2);%FFT along dim2
> F=fftshift(F,2);
> mtf=abs(F)'*abs(F);
> mtf_mean = mean(mtf,2);% Mean of all contents of a row
> mtf_mean_norm = mtf_mean/max(max(mtf_mean)); %Normalization to 1
> plot(mtf_mean_norm);
> plot(mtf_mean_norm);

Resources