Skip to content

Commit 787b9ea

Browse files
authored
Merge pull request #125 from kkoz/histogram-endpoint
Add Histogram JSON Endpoint
2 parents 953ac59 + ac6037d commit 787b9ea

File tree

9 files changed

+940
-47
lines changed

9 files changed

+940
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ image region microservice server endpoint::
136136
...
137137

138138

139-
location ~ ^/(webclient|webgateway)/(render_(thumbnail_ngff|image|image_region|image_region_rdef|image_rdef|shape_mask)|get_thumbnails_ngff)/ {
139+
location ~ ^/(webclient|webgateway)/(render_(thumbnail_ngff|image|image_region|image_region_rdef|image_rdef|shape_mask)|get_thumbnails_ngff|histogram_json)/ {
140140
proxy_pass http://image_region_backend;
141141
}
142142

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2023 Glencoe Software, Inc. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
19+
package com.glencoesoftware.omero.ms.image.region;
20+
21+
22+
import org.slf4j.LoggerFactory;
23+
24+
import io.vertx.core.MultiMap;
25+
26+
public class HistogramCtx extends MicroserviceRequestCtx {
27+
28+
private static final org.slf4j.Logger log =
29+
LoggerFactory.getLogger(HistogramCtx.class);
30+
31+
public static final String CACHE_KEY_FORMAT =
32+
"%d:%d:%d:%d:%d"; // ImageId, c, z, t, bins
33+
34+
/** Image ID */
35+
public Long imageId;
36+
37+
/** c - channel index */
38+
public Integer c;
39+
40+
/** Number of bins in the histogram */
41+
public Integer bins;
42+
43+
/** z - index */
44+
public Integer z;
45+
46+
/** t - index */
47+
public Integer t;
48+
49+
/** Max Plane Width */
50+
public Integer maxPlaneWidth;
51+
52+
/** Max Plane Height */
53+
public Integer maxPlaneHeight;
54+
55+
/** Set histogram min and max to the pixels type min and max rather than
56+
* the min and max values for the actual pixel values
57+
*/
58+
public boolean usePixelsTypeRange = false;
59+
60+
61+
/**
62+
* Constructor for jackson to decode the object from string
63+
*/
64+
HistogramCtx() {};
65+
66+
/**
67+
* Default constructor.
68+
* @param params {@link io.vertx.core.http.HttpServerRequest} parameters
69+
* required for retrieving the histogram.
70+
* @param omeroSessionKey OMERO session key.
71+
*/
72+
HistogramCtx(MultiMap params, String omeroSessionKey) {
73+
this.omeroSessionKey = omeroSessionKey;
74+
imageId = getImageIdFromString(getCheckedParam(params, "imageId"));
75+
c = getIntegerFromString(getCheckedParam(params, "theC"));
76+
String zStr = params.get("z") == null ? params.get("theZ") : params.get("z");
77+
if (zStr == null) {
78+
throw new IllegalArgumentException("Must provide either 'theZ' or "
79+
+ "'z' parameter");
80+
}
81+
z = getIntegerFromString(zStr);
82+
String tStr = params.get("t") == null ? params.get("theT") : params.get("t");
83+
if (tStr == null) {
84+
throw new IllegalArgumentException("Must provide either 'theT' or "
85+
+ "'t' parameter");
86+
}
87+
t = getIntegerFromString(tStr);
88+
maxPlaneWidth = getIntegerFromString(getCheckedParam(params, "maxPlaneWidth"));
89+
maxPlaneHeight = getIntegerFromString(getCheckedParam(params, "maxPlaneHeight"));
90+
bins = params.get("bins") == null ? 256 : getIntegerFromString(params.get("bins"));
91+
usePixelsTypeRange = getBooleanParameter(params, "usePixelsTypeRange");
92+
}
93+
94+
/**
95+
* Creates a cache key for the context.
96+
* @return See above.
97+
*/
98+
public String cacheKey() {
99+
return String.format(
100+
CACHE_KEY_FORMAT, imageId, c, z, t, bins);
101+
}
102+
}

0 commit comments

Comments
 (0)