Image is not displaying in Google Colab while taking input after imshow - python-imaging-library

I want to read an image from folder and display then from user input insert some details in dataframe. I need to loop 1000 images for annotation but i only see input not the image
'''
img =Image('/content/drive/MyDrive/dataset/images/01.jpg',cv2.IMREAD_UNCHANGED)
cv2_imshow(img)
id = input("Enter id ")
'''

Google colab crashes if you try to display image using cv2.imshow() instead import from google.colab.patches import cv2_imshow and display using cv2_imshow()
Reference: https://stackoverflow.com/a/57651882/12606908

Related

Get more of the metadata from the Neurotransmitter study using Allen SDK

I am downloading all the images from the Neurotransmitter study of the Allen Brain Atlas using this script:
from allensdk.api.queries.image_download_api import ImageDownloadApi
from allensdk.config.manifest import Manifest
import pandas as pd
import os
#getting transmitter study
#product id from http://api.brain-map.org/api/v2/data/query.json?criteria=model::Product
nt_datasets = image_api.get_section_data_sets_by_product([27])
#an instance of Image Api for downloading
image_api = ImageDownloadApi()
for index, row in df_nt.iterrows():
#get section dataset id
section_dataset_id= row['id']
#each section dataset id has multiple image sections
section_images = pd.DataFrame(
image_api.section_image_query(
section_data_set_id=section_dataset_id)
)
for section_image_id in section_images['id'].tolist():
file_path = os.path.join('/path/to/save/dir/',
str(section_image_id) + '.jpg' )
Manifest.safe_make_parent_dirs(file_path)
image_api.download_section_image(section_image_id,
file_path=file_path,
downsample=downsample)
This script downloads presumably all the available ISH experiments. However, I am wondering what would be the best way to get more of the metadata as follows:
1) type of ISH experiment, known as "gene" (for example whether an image is MBP-stained, Nissl-stained or etc). Shown in red circle below.
2) Structure and correspondence to the atlas image (annotations, for example to see to which part of brain a section belongs to). I think this could be acquired with tree_search but not sure how. Shown in red circles below from two different webpages on Allen website.
3) The scale of the image, for example how big one pixel is in the downloaded image (e.g., 0.001x0.001 mm). I would require this for image analysis with respect to MRI, for example. Shown below in the red circle.
All the above information are somehow available on the website, my question is whether you could help me to do this programmatically via the SDK.
EDIT:
Also would be great to download "Nissl" stains programmatically, as they do not show using the above loop iteration. The picture is shown below.
To access this information, you'll need to formulate a somewhat complex API query.
from allensdk.api.queries.rma_api import RmaApi
api = RmaApi()
data_set_id = 146586401
data = api.model_query('SectionDataSet',
criteria='[id$eq%d]' % data_set_id,
include='section_images,treatments,probes(gene),specimen(structure)')
print("gene symbol: %s" % data[0]['probes'][0]['gene']['acronym'])
print("treatment name: %s" % data[0]['treatments'][0]['name'])
print("specimen location: %s" % data[0]['specimen']['structure']['name'])
print("section xy resolution: %f um" % data[0]['section_images'][0]['resolution'])
gene symbol: MBP
treatment name: ISH
specimen location: Cingulate Cortex
section xy resolution: 1.008000 um
Without doing a deep dive on the API data model, SectionDataSets have constituent SectionImages, Treatments, Probes, and source Specimens. Probes target Genes, and Specimens can be associated with a Structure. The query is downloading all of that information for a single SectionDataSet into a nested dictionary.
I don't remember how to find the specimen block extent. I'll update the answer if I find it.

how to read text files from content repository

My requirement is read text files from content repository in sap abap.I used SCMS_DOC_READ FM to read image file and creating url DP_CREATE_URL for creating image url but SCMS_DOC_READ not working for text.
Can any one suggest some code, FM or class .
There are two options based on your requirement:
Option 1: Use READ DATASET to read file.
DATA : FNAME(60) type c VALUE 'myfile.txt',
TEXT2(5) type c.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
Option 2: Use Class CL_ABAP_CONV_IN_CE to read file.
Refer this tutorial page to get more information on this class.
You can easily find the answer there: http://scn.sap.com/thread/525075
If you want the short answer, you should use this(Note: I am not the author of this part):
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = "File path"
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT.
Note : Internal table structure should be same as text File.

Matlab - Name variable same as File name?

I'm building a facial recognition program and loading a whole bunch of images which will be used for training.
Currently, I'm reading my images in using double loops, iterating through subfolders in a folder.
Is there any way, as it iterates, that the images file name can be used before the image is read and stored?
eg. I have an image person001.jpg. How can you retrieve that name (person001) then read the image in like: person001 = imread('next iteration of loop which happens to be person001');
Thanks in advance.
I strongly recommend not to use unstructured variables. First it's very difficult to do operations like "iterate over all images", second you can get strange problems covering a function name with a variable name. Instead i would use a struct with dynamic field names or a map. A solution with a Map propably allows all possible file names.
Dynamic field names:
dirlisting=dir('.jpg');
for imageIX=1:numel(dirlisting)
%cut of extension:
[~,name,~]=fileparts(dirlisting(imageIX).name);
allImages.(name)=imread(dirlisting(imageIX).name);
end
You can access the images in a struct with allImages.person001 or allImages.(x)
Map:
allImages=containers.Map
dirlisting=dir('.jpg');
for imageIX=1:numel(dirlisting)
%cut of extension:
[~,name,~]=fileparts(dirlisting(imageIX).name);
allImages(name)=imread(dirlisting(imageIX).name);
end
You can access the images in a Map using allImages('person001'). Using a Map there is no need to cut of the file extension.

Generating image name with jpg extention in MATLAB using genvarname

I want to generate image name to read it later in the matlab code. I have name of the image in the work space as:
ImageName =
'OECA 2682_001_001'
I have done following to generate name and read image:
ext_img='*.jpg';
varname = genvarname(ImageName,ext_img)
image = imread('varname');
But varname is coming out to be :
varname =
x0x27OECA2682_001_0010x27
instead of OECA 2682_001_001.jpg. I want to read image as:
image=imread('OECA 2682_001_001.jpg');
How can I generate name of image with jpg extention to read image. Please help!
Thanks
That's not how genvarname works. You want to do:
varname = [genvarname(ImageName) '.jpg']
but I don't think you need genvarname at all. It's used for making a variable name, but you are not using it like that.
Also, instead of using
image = imread('varname');
you want
image = imread(varname);

Updating String in a matlab GUI

I am having quite a bit of trouble updating a string using a push button in my created matlab GUI. The goal would be to have this button preform a function on an image, whose string has been placed in a textbox on the GUI, then replace the old string with the new image's string
The main issue that I have run into is that I need the file to be in .raw format, but I am unable to figure out how I would accomplish that. I can replace the old string with a new string in .png format with the following code by adding it the guide GUI code.
handles.currentImage = imread(get(handles.Textbox1,'string'));
handles.currentImage = Addnoise(handles.currentImage); %addnoise is the function i created.
imwrite(handles.currentImage, 'photonoise', 'png');
pathname = 'C:\Documents and Settings\staff\My Documents\MATLAB\photonoise.png';
set(handles.Textbox1, 'string', fullfile(pathname));
But i am totally lost on how to make the string format a .raw. If there is some code I do not know about that i need to add to the GUI or to the Addnoise function, please let me know, I would greatly appreciate it.
Since .raw images are not supported by imwrite, you won't be able to use it. However, since .raw is a image format that isn't compressed this can be easily done using fwrite.
Here's an example using a 300 x 100 matrix of just zeroes (black):
cmodel=(zeros(300,100,1));
fid=fopen('blackimage.raw','w+');
cnt=fwrite(fid,cmodel,'uint8');
fclose(fid);
so in your case you'll need to modify this to the following:
fid=fopen('myimage.raw','w+');
cnt=fwrite(fid,handles.currentImage,'uint8');
fclose(fid);
Warning: my knowledge of the .raw format is pretty limited as well as imread so please take this with a grain (maybe even a cube) of salt